How to Update User Passwords in Linux

0


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:

FieldExampleMeaning
User NamesysadminThe name of the user.
Password StatusP

P indicates a usable password.

L indicates a locked password.

NP indicates no password.

Change Date03/01/2015The date when the password was last changed.
Minimum0The minimum number of days that must pass before the current password can be changed by the user.
Maximum99999The maximum number of days remaining for the password to expire.
Warn7The number of days prior to password expiry that the user is warned.
Inactive-1The 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

Post a Comment

0Comments
Post a Comment (0)