Atlantic.Net Blog

How to Change or Set User Passwords in Linux

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.

Change Your User Password

If you want to change your own password, use the passwd command-line utility as shown below:

passwd

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.

Also Read

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 hitesh@server-ip

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

Also Read

How to Find the Total Size of a Directory in Linux

Conclusion

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!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year