Site icon LinuxCommands.site

passwd command tutorial in linux/unix with examples and use cases

linux passwd command — modify a user’s password

A normal user may only change the password for his/her own account, while the superuser may change the password for any account.

Syntax

passwd [options] [LOGIN]

Options

Password rule

As a general guideline, passwords should consist of 6 to 8 characters including one or more characters from each of the following sets:

File

Exit values

The passwd command exits with the following values:

0 success
1 permission denied
2 invalid combination of options
3 unexpected failure, nothing done
4 unexpected failure, passwd file missing
5 passwd file busy, try again
6 invalid argument to option

Examples

1. Create a user and set a password

➜  ~ sudo useradd testUser
[sudo] password for ylspirit: 
➜  ~ passwd testUser 
passwd: You may not view or modify password information for testUser.
➜  ~ sudo passwd testUser
New password: 
Retype new password: 
passwd: password updated successfully

2. Switch users and display user status information

➜  ~ su testUser 
Password: 
$ passwd -S testUser     
testUser P 11/13/2019 0 99999 7 -1
$ 

3. Change user password

passwd testUser
Changing password for testUser.
Current password: 

4. Lock user

➜  ~ sudo passwd -l testUser
passwd: password expiry information changed.
➜  ~ su testUser
Password: 
su: Authentication failure

5. Unlock user

➜  ~ sudo passwd -u testUser
passwd: password expiry information changed.
➜  ~ su testUser
Password: 
$ 

6. Delete user password

➜  ~ sudo cat /etc/shadow | grep test
testUser:!$6$aNt2OgYyWHwVx27j$RIBsPbABNLLV8eQc0sT4E7dJEvmuHR7b/r.es4ExKjc6Un2GOJBZU.w9omJa/vvzuG8eKYGg6940Xe0eK93i90:18213:0:99999:7:::


➜  ~ sudo passwd -d testUser
passwd: password expiry information changed.


➜  ~ sudo cat /etc/shadow | grep test
testUser::18213:0:99999:7:::

Exit mobile version