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.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux queries.
In this context, we shall look into 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.
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. Here, you will learn how to modify the password of a user from the command line.
i. To change your own password,
Simply type the below command without sudo in your terminal window:
Now follow the prompt; enter your current and new password.
After doing so, your password will be changed.
ii. To modify 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 "linuxapt", the command would be:
$ sudo password linuxapt
After doing so, the password of the user will be changed.
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
$ 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.
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 "linuxapt" to change its password on the next login, the command would be:
$ passwd --expire linuxapt
This command will force expire the password for the user "linuxapt" and will ask it to set the password itself on its next login.
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.
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.
2. From the left window, switch to the Users tab. Then in the right window, click Unlock button.
3. 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.
4. Now choose the user account whose password you want to change. It can either be your account or another user's account.
5. In the 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 article covers how you can change user password in Linux either graphically or using the command line. Both Linux and UNIX-like operating systems use the passwd command to change user password.
This applies to any Linux distribution, including Alpine, Arch, Ubuntu, Debian, RHEL, Fedora, Oracle CentOS, SUSE/OpenSUSE and other popular Linux distros.
The passwd is used to update a user's authentication token (password) stored in /etc/shadow file.
To Set User Password in Linux:
Type following passwd command to change your own password:
To see all user account try grep command or cat command as follows:
$ cat /etc/passwd
$ grep '^userNameHere' /etc/passwd
$ grep '^linuxapt' /etc/passwd