As the name suggest **passwd** command is used to change the password of system users. If the passwd command is executed by non-root user then it will ask for the current password and then set the new password of a user who invoked the command. When this command is executed by super user or root then it can reset the password for any user including root without knowing the current password.
In this post we will discuss passwd command with practical examples.
#### Syntax : ####
# passwd {options} {user_name}
Different options that can be used in passwd command are listed below :
When you logged in as non-root user like ‘linuxtechi’ in my case and run passwd command then it will reset password of logged in user.
[linuxtechi@linuxworld ~]$ passwd
Changing password for user linuxtechi.
Changing password for linuxtechi.
(current) UNIX password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[linuxtechi@linuxworld ~]$
When you logged in as root user and run **passwd** command then it will reset the root password by default and if you specify the user-name after passwd command then it will change the password of that user.
In the above output first field shows the user name and second field shows Password status ( **PS = Password Set , LK = Password locked , NP = No Password** ), third field shows when the password was changed and last & fourth field shows minimum age, maximum age, warning period, and inactivity period for the password
### Example:3 Display Password Status info for all the accounts ###
To display password status info for all the accounts use “**-aS**” option in passwd command, example is shown below :
### Example:6 Lock the password of System User ###
Use ‘**-l**‘ option in passwd command to lock a user’s password, it will add “!” at starting of user’s password. A User can’t Change it’s password when his/her password is locked.
### Example:7 Unlock User’s Password using -u option ###
[root@linuxworld ~]# passwd -u linuxtechi
Unlocking password for user linuxtechi.
passwd: Success
[root@linuxworld ~]#
### Example:8 Setting inactive days using -i option ###
-i option in passwd command is used to set inactive days for a system user. This will come into the picture when password of user ( in my case linuxtechi) expired and user didn’t change its password in ‘**n**‘ number of days ( i.e 10 days in my case) then after that user will not able to login.
### Example:10 Set Warning days before password expire using -w option ###
‘**-w**’ option in passwd command is used to set warning days for a user. It means a user will be warned for n number of days that his/her password is going to expire.