How to Change a Password in Linux

How to Change a Password in Linux

Passwords are the first line of defense when securing any system, including Linux. Passwordless SSH is a reliable alternative, but at the end of the day, a strong password is one of the best options. Having a strong password makes your system much more reliable. In this tutorial, you’ll learn how to change a password on any Linux distribution, including Ubuntu, Debian, and CentOs.

We will also teach you how to change it for other users on your VPS. That is ideal if you are trying to learn the skill set of a sysadmin.

How to Change a Password in Linux?

To change the password you only need to know one command. First, access your VPS through SSH. Having trouble? Check out our PuTTY tutorial. Then, to change the password in Linux you need to open the terminal and type the following command:

sudo passwd

After executing the command, you will be asked to enter the new password twice. In this case, when we’re not specifying a user, we’ll be changing the root password. The output should look like this:

Enter new UNIX password:
Retype new UNIX password:

If you change your password successfully, the command line will output something like this:

passwd: password updated successfully

This means your new password is set and your old password is long gone.

How to Change a Password in Linux for Another User?

It is also possible to change the current password of another user in the same system. To do this, you will need to use the passwd command once again.

First, log in as the root user, type passwd followed by the user’s name whose password you want to change. The command would look like this in the command line:

passwd user_name

In this case, if you want to change the password of the user named edward. The command line would look like this:

passwd edward

Next, we will be prompted by the same request to enter the new password twice.

Enter new UNIX password:
Retype new UNIX password:

And just like that, you have updated a different user old password, to a new password, by using the passwd command.

Passwords and Linux

Linux is considered one of the safest systems in the world because of the way processes are handled. However, every operating system depends on the security of their passwords, at some point. Linux manages these passwords in a very similar way to other systems. However, it is necessary to know two important directories in password management.

The first of these files is /etc/passwd where we can find all users’ on the system. In addition, it shows which group of the system the passwords belong to. It is possible that you will see many users, but only a few will be able to log in as they are system users.

If you want to see the content of /etc/passwd, you can do it with the following command:

cat /etc/passwd

The second Linux file that is strongly related to passwords is /etc/shadow. In the shadow file, you will be able to see the encrypted passwords of users and if they have an SSH key and other related information.

cat /etc/shadow

How to Create a Strong Password

Finally, it is recommended that we establish strong passwords so that no one can hack them. It is suggested that you choose a password that is unique, long, and avoids using personal information.

To create or change to a unique password, use a different password for each of your important accounts, such as online banking and email accounts. Try not to reuse your past passwords.

To create or change a longer and more memorable password, try your favorite line from a song, book, or movie. You can also take longer lines and just use the first letter of each word.

Remember not to use personal information in your password as well. Avoid nicknames, initials, pet names or old street addresses.

If you suspect that one of your passwords has been compromised, change it as soon as possible. It is also advised to do this frequently.


Changing a password in Linux is important for the security of your project. The process is very simple, and we recommend doing it frequently for maximum security. Stay safe out there!

The Author


Edward S. / @edvardasstabinskas

Edward is Hostinger's copywriter. He's an expert communicator with years of experience in IT as a writer, marketer, and Linux enthusiast. IT is a core pillar of his life, personal and professional. Edward's goal is to encourage millions to achieve an impactful online presence. He also really loves dogs, guitars, and everything related to space.

Related tutorials

Leave a reply




This site uses Akismet to reduce spam. Learn how your comment data is processed.

Become a part of Hostinger now!

More in VPS
How to Use the Linux Ping Command