The passwd
command is used to update a user’s password. Users can only change their own passwords, whereas the root user can update the password for any user.
passwd [OPTIONS] [USER]
For example, since we are logged in as the sysadmin
user we can change the password for that account. Execute the passwd
command. You will be prompted to enter the existing password once and the new password twice. For security reasons, no output is displayed while the password is being typed. The output is shown as follows:
sysadmin@localhost:~$ passwd
Changing password for sysadmin.
(current) UNIX password: netlab123
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
If the user wants to view status information about their password, they can use the -S
option:
sysadmin@localhost:~$ passwd -S sysadmin sysadmin P 12/20/2017 0 99999 7 -1
The output fields are explained below:
Field | Example | Meaning |
---|---|---|
User Name | sysadmin | The name of the user. |
Password Status | P |
|
Change Date | 03/01/2015 | The date when the password was last changed. |
Minimum | 0 | The minimum number of days that must pass before the current password can be changed by the user. |
Maximum | 99999 | The maximum number of days remaining for the password to expire. |
Warn | 7 | The number of days prior to password expiry that the user is warned. |
Inactive | -1 | The number of days after password expiry that the user account remains active. |
Follow Along
Switch the root
account using the following command. Use netlab123
as the password:
sysadmin@localhost:~$ su root Password: root@localhost:~#
The root user can change the password of any user. If the root user wants to change the password for sysadmin
, they would execute the following command:
root@localhost:~# passwd sysadmin Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Follow Along
Exit the root
account using the exit
command:
root@localhost:~# exit exit