Linux and UNIX-like operating systems provide the passwd command to reset or change the user password. The passwd command is used to change the passwords for user and group accounts. A normal user can change the password for his/her own account whereas the superuser (or root) can change the password for any other account. The passwd changes the user password by updating a user’s authentication token (password) stored in /etc/shadow file.
Linux set or reset user password
To change the password, type the below command and press enter –
# passwd Sample Output
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfullyLinux change password for another user account
To reset or change the password for any other user, type the below command with username and press enter –
# passwd kodehelpSample Output
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfullyAs a Linux system administrator (sysadmin) you can change password for any users on your server. To change a password on behalf of a user:
- First, sign on or
suorsudoto therootaccount on Linux, run:sudo -i - Then type,
passwd jerryto change a password forjerryuser - The system will prompt you to enter a password twice as below
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfullyForce Linux user to change password on next login
By default, Linux passwords never expire for users. However, we can force users to change their password the next time they log in via GUI or CLI methods. Execute below command to force user to change password on next login –
# sudo passwd -e jerry
# sudo passwd --expire jerryThe passwd command is used to update or change the user’s password. The encrypted password is stored in /etc/shadow file and account information is in /etc/passwd file.