howtouselinux

2 ways to change user password in Linux

Table of Contents

Do you need to change your user password in Linux? Are you not sure how to do it? Don’t worry, we will show you how! There are two ways that you can change your password in Linux. In this blog post, we will show you how to use both of these commands. Let’s get started!

understanding passwd command in Linux

The “passwd” command is a utility that allows you to change passwords for users on a Linux system. The “passwd” command can be used to change the password for any user, including the root user. When you use the “passwd” command, you will be prompted to enter the old password and the new password twice. 

change user password with passwd command in Linux

The easiest way to change the user password in Linux is using passwd command. First, open a terminal window. Then, type in the passwd command. You will then be prompted to enter the old password and new password twice. Once you have done so, the user’s password will be changed.

Example:
$ passwd
Changing password for user howtouselinux.
Changing password for howtouselinux.
(current) UNIX password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

If you are a root user or you have sudo privileges to reset password, you can change the password for another user in Linux. Run passwd command and specify the user’s name.

  • Open a terminal.
  • Type in the passwd command along with the user name.
  • Type the user’s password, and confirm the change.

 

The “passwd” command can also be used to expire passwords. To do this, use the following command: passwd -e username. The user’s password will then be expired and they will be required to enter a new password the next time they log in.

You can also use the “passwd” command to change the password for a user who is not logged in. To do this, use the following command: passwd  username. The user’s password will then be changed and they will be able to log in with the new password.

Finally, you can use the “passwd” command to lock or unlock a user’s account. To lock an account, use the following command: passwd -l username. The user will not be able to log in until the account is unlocked.

To unlock an account, use the following command: passwd -u username. Replace “username” with the actual username of the user whose account you want to unlock. The user will then be able to log in.

‘-i’ option in passwd command is used to set inactive days for a system user. This will come into the picture when the password of a user is expired and user didn’t change its password in ‘n’ number of days ( i.e 10 days in my case) then user will not able to login and its account will be disabled.

To display user / account status information, use -S option in passwd command. User’s status information consists of seven fields as shown below.

# passwd -S howtouselinux
howtouselinux PS 2022-09-20 0 99999 7 -1 (Password set, SHA512 crypt.)

In Linux, we can force system users to change its password in n number of days using ‘-n’ in passwd command. In the below example, linuxtechi user has to change its password in 90 days. 

# passwd -n 90 test
Adjusting aging data for user test.
passwd: Success

By following the steps above, you can easily change, expire, or lock a user’s password in Linux. I hope this has been helpful. If you have any questions, please feel free to leave a comment below and I will do my best to answer them.

 

Tips to change user password in Linux

There are a few things to keep in mind when changing a user’s password in Linux. First, make sure that you use a strong password. A strong password should be at least 8 characters long and contain a mix of upper and lower case letters, numbers, and symbols. You can use the pwgen command to generate a random, strong password.

It is also a good idea to avoid using easily guessed words or phrases in your password. For example, using your name or birthday as your password is not recommended. Instead, try to come up with a phrase that is meaningful to you but would be difficult for someone else to guess.

Remember to change your password regularly. This will help to ensure that your account remains secure.

Second, keep in mind that changing a user’s password will also change the password for any services that the user has set up. So, if the user has a website that is hosted on their account, they will need to update the password for that as well.

Finally, if you are the root user, you can change any user’s password. However, it is generally considered good practice to only change your own password and let each user change their own password.

That’s all there is to changing a user’s password in Linux. By following the steps above, you can easily change the password for any user on your system.

What to do if you forget your password in Linux

If you forget your password in Linux, don’t worry – there are a few ways to reset it. One way is to use the “passwd” command. To do this, you will need to be logged in as the root user. Once you are logged in as root, type the following command at the prompt: passwd username

Replace “username” with the actual username of the user whose password you want to reset. You will then be prompted to enter the new password twice. Once you have done so, the user’s password will be reset and they will be able to log in with the new password.