When working in a Linux operating system, a password is the first line of defense to secure the system. It is recommended to change the user password in Linux to reinforce security and make the system harder to breach. passwd is a command-line utility in Linux used to update a user’s authentication password stored in /etc/shadow file. A root or superuser can change the password of any user account while a normal user can only change the password for his/her own account.
When changing a user password in Linux, you should follow the below guidelines:
- A password must be strong, at least eight characters or more.
- Use both upper and lowercase letters to make to the password strong.
- Avoid any dictionary word, your name, surname, or your birth date in a password.
In this post, we will show you how to change or set user passwords in Linux.
- A server running Linux on the Atlantic.Net Cloud Platform
- A root password configured on your server
Create Atlantic.Net Cloud Server
First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing any Linux operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.
Change Your User Password
If you want to change your own password, use the passwd command-line utility as shown below:
You will be asked to provide your existing password in order to set the new password. Once the password is correct, you will be asked to provide a new password as shown below:
Changing password for vyom. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
After setting up a new password, you can use it on the next login.
How to Install and Use Ping Command in Linux
Change Another User’s Password
Only a root user or a user with sudo privileges can change the password of another user. Use the following syntax to change the password of the other user:
sudo passwd username
For example, to change the password of the user named vyom, run the following command:
sudo passwd vyom
You will be asked to provide and confirm the new password:
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Force User to Change a Password at Login
If you are working in a multi-user environment, then it is recommended to force a user to change their password the next time they log in.
Use the following command to force the user named hitesh to change a password at the next login:
sudo passwd --expire hitesh
This command will expire the user password. When the user tries to log in with the old password, they will see a message asking them to change their password:
ssh [email protected]
You should see the following message:
[email protected]'s password: You are required to change your password immediately (root enforced) WARNING: Your password has expired. You must change your password now and login again! Changing password for hitesh. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
How to Find the Total Size of a Directory in Linux
In this guide, we explained how to set or change a user password in Linux. This procedure will work on any Linux operating system including Ubuntu, Debian, RHEL, Fedora, CentOS, Rocky Linux, Oracle Linux, Alpine, Arch, and more. Try it on VPS hosting from Atlantic.Net!