The passwd command in Linux is used to change user passwords efficiently. This command updates an authentication token/password for a user that is stored in your system’s /etc/shadow file. A standard user in Linux can change their own password, however, a superuser can change the password for any other user as well. When you are setting a new password, it is a good security practice to choose a complex one. A complex and secure password has the following properties:
- It includes both upper and lower case letters
- It includes digits from 0 to 9
- It has special characters and punctuation marks
- It is a lot different than your previous passwords
- It does not include information such as your full name, address, phone number, birth date, or license numbers. This information can easily be used to guess your password.
Always note down your password in a secure location from where it can not be fetched. It would help you in remembering the password in case you forgot it.
In this article, we will tell you how you can manage user passwords in Linux through the command line and GUI. We have run the commands and processes mentioned in this article on a Debian 10 Buster system but you can replicate them on most Linux distros.
Changing Password Through the UI
If you are a Linux user who prefers the graphical user interface to perform most administrative operations, you can use the Settings utility on your system.
There are two ways in which you can access the system Settings.
- Access the Application Launcher through the Super/Windows key and then enter the keywords ‘settings’ in the search bar as follows:
- Click the downward arrow in the top panel of the Debian/Ubuntu desktop and then click on the ‘settings’ icon from the following drop-down menu:
In the Settings utility, select the Details tab from the left panel and then select the Users tab on it to open the Users settings view. This is how the Users view looks like:
All the users on your system will be listed here. Click on the user whose details you want to change. You need to first unlock the Users view so that you can make changes to its settings. Please remember that only an authorized user/administrator can unlock the view. Click the Unlock button and enter your credentials as follows:
As you click the Authenticate button, the fields on the Users view will become active and you can make changes to them.
Click on the Password field and the following Change Password view will open. Enter the New Password, and then enter the same password again in the Confirm New Password field. You will now be able to see the Change button active.
Click on the Change button and the password for the selected user will be changed.
Tip: One easy and quick way to access the Users settings is to enter the keyword ‘Users’ in the Application Launcher as follows:
Changing Password Through the Command Line
The Linux command line gives an administrator much more power than the UI, to make user and system settings. In order to launch the default command line application on Linux Debian and Ubuntu, open the Application Launcher and enter the ‘Terminal’ keywords as follows:
As the Terminal opens, you can do the following with user passwords:
- Change your own password
- Change password for another user
- Change the password for sudo
Changing Your Own Password
A non-administrator on Linux can only change their own password. The passwd command is used to change user passwords in Linux. This is how a user can use this command to change their own password:
As you enter the passwd command, the system prompts you to enter your current password. As you do so, this password is checked against the stored password. If it matches, you are proceeded to the next step i.e, to enter the new password. After you enter the new password, the system then asks again to type the new password for confirmation. After the two entries match, your password will be successfully changed.
Changing Password for Another User
On Linux, only an administrator/superuser can change the password for another user. This is the command a superuser will be using:
As a user enters this command, they will be asked the password for sudo to ensure that they are indeed a super user. A super user is not required to enter the old password for a user as they might be using the command to reset a forgotten password. Anyways, the super user is also required to enter and re-enter the new password, after which, it is updated successfully.
Changing the Password for sudo
It is a good security practice to change a super user’s password on Linux from time to time. Here are two ways through which you can change a sudo password:
Method 1:
The first way is to log in as root through the following command:
When you are logged in as root after entering a valid password, use the passwd command to change the password for root.
You can then exit the root prompt through the exit command as follows:
Method 2:
The second method is to use the following command as sudo:
Enter the password for sudo and then you can change the password of root, like you do for any other user.
This was all you needed to know about changing user passwords in Linux, both through the UI and the command line. You can now maintain a much secure user account on your system.