How to Change a Password in Linux
This tutorial will show you how to change your password in Linux.
Encrypted passwords are stored in the /etc/shadow file.
If you are not a root user you can only change your own password. In order to change the password of another user or the system password you must be an Admin, a root user.
It is highly recommended to have a strong complex password. Strong passwords usually have at 16 characters, at least one uppercase and one lowercase letters, and at least one number and one special character.
Be smart in your choice of passwords.
Lastpass is an excellent source for password storage as well as generating complex random passwords.
1. To change your own user account password run the passwd command without any options:
You will be prompted to enter your current password. If the password is correct you will be asked to enter and confirm the new password.
Passwords will not be displayed on the page when you enter them.
On your next login the new password will take effect.
2. Update another user’s password.
Only the root user and users with sudo access can change the password for another user account.
To change the password of another user account, run the passwd command followed by the username.
For example, if the username is devops you will run the following command:
$ sudo passwd devops
You will then be prompted to enter the new password. Once you have confirmed the password you will receive the message:
passwd: password updated successfully
3. Force User to Update Password at Next Login
If you are the root user and want to force the user to update their credentials they next time they logon enter the following command:
$ sudo passwd –expire devops
Upon login the user will receive the message WARNING: Your password has expired.
The user will be prompted to enter their current password and a new password. Once the user resets the password the connection will be closed and they can login normally.
It is strongly recommended to update your password on a regular basis.
The passwd command line utility is used to update or change user’s password. The encrypted password is stored in /etc/shadow file and account information is in /etc/passwd file. To see all user account try grep command or cat command as follows:
grep ‘^userNameHere’ /etc/passwd
grep ‘^tom’ /etc/passwd