passwd command in Linux with Examples

Password command

Password command is used to change the password for user accounts. User may change the password for their own account while the super user (root) may change the password for any account. Using this command, the validity period of the password can also be changed.

 

Syntax

passwd <options> <User-name>

 

Options
-a, --all      : It is used only with -S and shows status of all users.
-d, --delete : Deletes a user's password then it makes empty.
-l, --lock     : Locks password entry for rename.
-f, --force    : Force the user to change password at the next login by expiring the password for name.
-S, --status : To report the password status on the named account. It contains 7 fields in the status information
-u, --unlock : unlock the password of named account.

 

Change Password of System Users

passwd command is used to change the password of system user. Changing Password from root user

 

Example

[root@linuxhelp ~]# passwd user1 
Changing password for user user1.
Changing password for user1.
(current) UNIX password:
New password:
Retype new password:
Passwd: all authentication tokens updated successfully.

 

Changing password from its own user

Example

[user1@linuxhelp ~]$passwd 
Changing password for user user1.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

 

Display Password Status Information

passwd command is used to view the password status information about the users by using –S option.

 

Example

[root@linuxhelp ~]# passwd -S user1 
user1 PS 2016-02-03 0 99999 7 -1 (Password set, SHA512 crypt.)

 

Removing Password of a User

To remove the Password of a user, the password command with option ‘d’ is used.

 

Example

[root@linuxhelp ~]# passwd -d user1 
Removing password for user user1.
passwd: Success
     
[root@linuxhelp ~]# passwd -S user1 
user1 NP 2016-02-03 0 99999 7 -1 (Empty password.)     

Set Password Expiry Immediately

passwd command is used to set the password expiry immediately for a user using -e option. This will force the user to change the password in the next login.

 

Example

[root@linuxhelp ~]#passwd  -e  user2 
Expiring password for user user2.
passwd: Success
[root@linuxhelp ~]# passwd  -S  user2 
user2 PS 1969-12-31 0 99999 7 -1 (Password set, SHA512 crypt.)

 

Example

[user1@linuxhelp ~]# ssh user2@192.168.7.13 -p24865 
user2@192.168.7.13's password:
You are required to change your password immediately (root enforced)
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user user2.
Changing password for user2.
(current) UNIX password:

 

Lock the password of System User

passwd command is used to lock the password for a user using -l option.

 

Example

[root@linuxhelp ~]# passwd -l user1 
Locking password for user user1.
passwd: Success
[root@linuxhelp ~]# passwd -S user1 
user1 LK 1969-12-31 0 99999 7 -1 (Password locked.)

 

Unlock User’s Password

passwd command is used to unlock the user's password for a user using -u option.

 

Example

[root@linuxhelp ~]# passwd -u user1 
Unlocking password for user user1.
passwd: Warning: unlocked password would be empty.
passwd: Unsafe operation (use -f to force)
         
[root@linuxhelp ~]# passwd -f user1 
Changing password for user user1.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

 

Set the inactive days for a user

passwd command is used to set the inactive days for a user using -i option.

 

Example

[root@linuxhelp ~]# passwd  -i  7  user1 
Adjusting aging data for user user1.
passwd: Success
[root@linuxhelp ~]# passwd -S user1   
user1 PS 2016-02-03 0 99999 7 7 (Password set, SHA512 crypt.)

 

Set Minimum Days to Change Password

passwd command is used to set the minimum days to change password for a user using -n option.

 

Example

[root@linuxhelp ~]# passwd -n 60 user1 
Adjusting aging data for user user1.
passwd: Success
[root@linuxhelp ~]# passwd -S user1 
user1 PS 2016-02-03 60 99999 7 7 (Password set, SHA512 crypt.)

 

To Set Warning days before password expiry

passwd command is used to set the warning days before user's password expire for a user using -w option.

 

Example

[root@linuxhelp ~]# passwd -w 10 user1 
Adjusting aging data for user user1.
passwd: Success
[root@linuxhelp ~]# passwd -S user1 
user1 PS 2016-02-03 60 99999 10 7 (Password set, SHA512 crypt.)

Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website www.linuxhelp.com
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: password command
user image Author :  Benjamin