Learn How to Change a Password on Linux

In this quick guide, we will show you how to change your user’s password on a Linux-based operating system.

Linux Change Password

A password is often used on Linux to authenticate a user and prevent unauthorized access to your system and data.

From time to time, you may want to change the password of your user, the root user, or another user on your system. Luckily, Linux makes changing the password from within the terminal a relatively simple process thanks to the passwd command.

Learning how to change a password on Linux is great, as what you learn here will work on almost any other Linux distribution you use, including Ubuntu, Debian, RHEL, and more.

If you are the root user on your Linux system, it is even possible to change the password of other Linux users. Or, if you would prefer a user to set their own password, you can simply expire their password, which will force them to change it when they log in.

Changing Your Password in the Linux Terminal

By default, most Linux operating systems give the current user full control over their password. As you will soon see, you can easily change this from within the terminal.

1. Once you have the terminal open on your Linux device, you can begin to change the password on your Linux system by using the “passwd” command.

passwd

2. You will now be notified who you are changing the password for. Since you ran this without specifying any options, this will be changing the password of the current user.

If you have a password set for this account, you must type it out before you can change it.

Changing password for pi.
Current password:

3. Next you will need to specify a new password to use for your Linux account.

New password:

4. To ensure you don’t accidentally lock yourself out of your account by mistyping the password, you will be asked to specify it again.

Retype new password:

5. If everything has worked correctly, you should see a message like the one below indicating that you successfully updated the password of your Linux user.

passwd: password updated successfully

How to Change the Root User’s Password on Linux

It is also possible to change the root user’s password on Linux using the same passwd command that you used to change your users.

Of course, to adjust the root user’s password, your own user will need superuser privileges or access to the root user itself.

1. To update the Linux root user’s password, you will want to use “sudo“, followed by the “passwd” command, and then “root“.

Specifying the root user specifically ensures we adjust the root password, not your own account.

sudo passwd root

2. Since we ran this command as a superuser, you won’t be asked to enter the existing password.

You will now want to type out the password that you want to use to access your root user.

New password:

3. To prevent locking yourself out of your root user, you must type out the password again.

Retype new password:

4. If everything has worked correctly, you should see the following message indicating that you successfully updated the Linux root user’s password.

passwd: password updated successfully

Using the Terminal to Change Another Users Password

If you are the root user or you have superuser privileges, you will actually be able to change the password for any user that exists on your system. This is useful for fixing an account where you forgot the password, or one of your users got locked out of their account.

This section will show you how to use the passwd command to change the password of any Linux user.

1. With the terminal open, changing another Linux user’s password is incredibly simple, and again uses the “passwd” command.

Here, you want to ensure you run the “passwd” command with “sudo” This ensures you are executing the command as either the root or superuser.

After the passwd command, you must specify the name of the user for whom you want to change the password.

sudo passwd <USERNAME>

For example, if we wanted to change the password of a Linux user called “pimyubu” we would use the following command in the terminal.

sudo passwd pimyubu

2. You will now be prompted to specify the new password for your chosen user.

New password:

3. To confirm the password change, you will need to type out the new password again. This helps prevent you from setting an incorrect password for your chosen Linux user.

Retype new password:

4. Once the password has successfully been updated for your desired user you will see the following message.

passwd: password updated successfully

Force a User to Change Their Password on Login

Only in some cases will you want to have to set a user’s password on Linux yourself. This is where Linux’s password systems expiry system comes in hand. By expiring a password on Linux, you force that user to type out a new password the next time they log in.

To expire a password on Linux, you will still use the “passwd” command from before. But this time, we will need to use the expire option.

1. The major change between changing your Linux users password and expiring it is including the “-e” option. This option tells the passwd command to expire the password for a given user.

sudo passwd -e <USERNAME>

For example, we would run the following command to expire the password for our “pimyubu” user.

sudo passwd -e pimylifeup

2. After expiring a users password on Linux, you will simply see a message saying that the “password changed”.

Next time the user logs in, they will be told they must change their password.

passwd: password changed.

3. For example, when switching over to our “pimyubu” user, we will be greeted with a warning that our password has expired and we can’t log in till we update our password.

Before you can update your user’s password, you must type in what it is currently set to.

WARNING: Your password has expired.
You must change your password now and login again!
Changing password for pimyubu.
Current password:

4. Next, you will be prompted to type in the new password you want to use for your account. You will not be able to set the same password you used previously.

New password:

5. To ensure you haven’t mistyped your password, you will be prompted to type it out again.

Retype new password:

6. Assuming everything has worked, you should see a message that your password has been updated successfully. You will also be automatically logged out, so if you have an SSH session, this will be terminated.

Simply log back in using the password you just set.

passwd: password updated successfully

Conclusion

Hopefully, by this point in the tutorial, you will understand how easy it is to update a user’s password on Linux.

The passwd command is incredibly powerful and easy to use. Best of all, it is basically available on almost every Linux-based system, so it is well worth learning how you can utilize it.

Please feel free to leave a comment below if you have any questions about changing the password of a Linux user.

If you found this quick guide helpful, we have plenty of other Linux guides worth checking out.

Leave a Reply

Your email address will not be published. Required fields are marked *