CentOS Ubuntu

How to Change User Password in Linux

How to Change User Password in Linux

Your systems carry a lot of confidential and important data. One of the most effective ways to protect and safeguard your system from unauthorized access is to use a strong password. Generally, when you install Ubuntu, you create users and assign passwords and you don’t feel the need to change them. However, there are some scenarios where you need to change it like if you have a weak password and you want to set a new strong password. Similarly, as a system administrator, you might need to modify the passwords of users. Whatever the reason it might be, you can easily change the user password in Linux either through the command line or through the GUI.

This guide will explain how to change the password for your and other user accounts through both the command line and GUI. It will also cover changing the password for the root account and forcing a user to change their password at the next login.

Note: We have tested the commands described here on Ubuntu 20.04 LTS. However, the same commands also work for other Linux distributions.

Change User Password through Command Line

In Linux, you can do almost everything with the command line using only a single command. The same goes true with changing the user’s passwords. In this method, we will show how to modify the password of a user from the command line.

Change Your Own Password

To change your own password, simply type the below command without sudo in your terminal window:

$ passwd

Now follow the prompt; enter your current and new password.

After doing so, your password will be changed.

Change Password for Another User

To change the password for another user, you will need sudo privileges or will have to switch to the root account. Use the command below for changing the password for any other user:

$ sudo passwd <username>

For instance, to change the password for a user named “sim”, the command would be:

$ sudo password sim

After doing so, the password of the user will be changed.

Change Root Password

When you install the Ubuntu system, there is no root password set; you have to manually set it. A sudo user can change the password of a root account. To set the root password or if you have already set it but want to change it, then use any of the below commands:

$ sudo passwd

Or

$ sudo passwd root

First, provide the password for sudo, and then enter the new password that you want to set for the root account.

After doing so, the password of the root account will be changed.

Force a User To Change Its Passwords

If a system administrator has created user accounts and set passwords itself, then he can force the users to change their passwords at the next login. It can be done through the passwd command with –expire option as follows:

$ passwd --expire <username>

For example, to force a user named “sim” to change its password on the next login, the command would be:

$ passwd --expire sim

This command will force expire the password for the user “sim” and will ask it to set the password itself on its next login.

Change Password through GUI

If you prefer working in a graphical environment rather than working on the command line, you can use the below-described method for changing the password for a user account.

Step 1: Open Settings application in your system. You can do so right-clicking the desktop and choosing Settings from the appeared menu. Alternatively, you can press the super key and in the search area, type settings. Then from the search results, select the Settings utility.

From the left window, switch to the Users tab. Then in the right window, click Unlock button.

Now you will be asked to authenticate by providing the password and then clicking the Authenticate button. After doing so, user settings will be unlocked.

Now choose the user account whose password you want to change. It can either be your account or another user’s account.

In the following dialog box, type your current password. After that in the next fields, type new password. Then click Change to apply it.

After you complete the steps, the password of the user will be changed.

This is how you can change user password in Linux either graphically or using the command line. This post covered how to change password for current user account, for any other user and the root account. Hope it helps!

Similar Posts