Home Linux Commands How to Change or Set User Password in Linux

How to Change or Set User Password in Linux

As a regular user, you have a password that safeguards your account, and this account contains all your personal settings and files and therefore requires important protection.

Hence, it is a good practice to change your password consistently to decrease the possibility that someone else gets to recognize your password and can use your credentials to authenticate.

[ You might also like: How to Restrict SSH Access to Certain Users in Linux ]

When changing a user password, make sure it meets the following minimal requirements:

  • A password must be strong: at least six or eight characters or more is better.
  • Make sure to use complex passwords by mixing letters, numbers, and other characters to make the password as hard to guess as possible.
  • Use upper and lowercase letters to make the password harder to crack by an attacker.
  • Make sure to avoid using any dictionary word as a password, because attackers use a brute-force password cracker to scan the whole contents of a dictionary, and if your password is in the dictionary, they can easily crack it.

[ You might also like: How to Get Information About Other Linux Users ]

Changing a User Password in Linux

Changing a user password is not that hard, just use the passwd command to change the password of your own account (it could be a root user or regular user).

$ passwd

Now, you need to enter your old password, as this is to prevent others from changing your password. Next, you need to enter the new password twice and make sure that your password meets the complexity rules as explained above; else, it will not be changed.

Change User Password in Linux
Change User Password in Linux

If you are logged in as a root user, you can change the password of other system users by typing the passwd command followed by the name of the user whose password you want to change.

$ passwd linuxshelltips

It won’t prompt you for the old password, since you are logged in as a root user, you should be able to change the user’s passwords without knowing the old password.

Change Other User Password in Linux
Change Other User Password in Linux

Managing Linux Users with the passwd Command

There are other useful options that you can use while changing a user’s password and they are:

Remove User Password in Linux

Use the -d argument to remove the password for the specified user account.

$ passwd -d linuxshelltips
Remove User Password in Linux
Remove User Password in Linux

Lock User Password in Linux

Use the -l argument to lock the password for a user account if it is not used for a given period of time.

$ passwd -l linuxshelltips
Lock User Password in Linux
Lock User Password in Linux

Unlock User Password in Linux

Use the -u argument to unlock the user password that has been locked with -l option.

$ passwd -u linuxshelltips
Unlock User Password in Linux
Unlock User Password in Linux

Force User to Change Password in Linux

Use the -e argument to force the user to change the password during the next login attempt.

$ passwd -e linuxshelltips
Force User Password Change in Linux
Force User Password Change in Linux

The passwd command is pretty useful to manage system users on your Linux system. It manipulates the user entries in the /etc/passwd file, and the system administrator must have this as a toolkit.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.