Passwords are the primary protection component in computing devices. Passwords must be frequently changed to keep the system secure. they must be changed frequently to keep the system secure. In Linux, a user’s password can be changed either using the GUI or the terminal. This post will list the possible methods to change a user’s password in Linux. The post’s content is listed as follows:
- Method 1: Using the Command-Line Interface
- Method 2: Using the Graphical-User Interface
Let’s get started!
Method 1: Using the Command-Line Interface
All Linux distributions are managed by running different commands so that we can change the password of the Linux distributions by two methods, either by using the “passwd” command or the “chpasswd” command; both methods are explained in detail in the next sections.
Method 1.1: Using the passwd Command
The “passwd” command utility in the Linux distributions is used to manage user passwords. The general syntax of using the passwd command utility in Linux:
$ passwd [username]
The “username” argument is optional. If it is not provided, then the “passwd” utility will change the password of the currently logged-in user.
Let’s practically implement this command:
How to Change the Password of a Current User in Linux?
Here, use the following command to change the password of the current user:
$ sudo passwd
After running the command, you have to enter the new password (minimum 8 characters), and it will ask you to retype; once done, the password of the user will be changed.
Note: The password for the current user can also be changed by specifying its “username”.
How to Change the Other User Password in Linux?
There can be different users in Linux, and we can also change the password of any other user by using the “passwd” command by specifying its name. For example, to change the password of the user “john”, we will use the command:
$ sudo passwd john
The password of the user “john” has been changed to the set password.
Method 1.2: Using the chpsswd Command
The “chpasswd” command can also be used to update the passwords of the Linux users in batch mode. To use this option, we will follow the general command usage syntax:
$ echo "username:<newpassword>" | chpasswd
To understand the above usage of the command, we will update the password of the user named “itslinux”:
echo “itslinux:@qwer1234” | chpasswd
The password of the “itslinux” has been updated successfully.
Similarly, to explore more options of the “chpasswd” command, use the “–help” option:
$ chpasswd --help
All these options displayed on the screen can be used with the “chpasswd” command.
Note: The “chpasswd” command should be run as a root user, and to switch the root user, you can use the “sudo -s” command.
Method 2: Using the Graphical-User Interface
The GUI is the simplest way to understand anything. We can use this for changing the user password; type “Settings” in the search console of the application’s menu. These steps are performed on Ubuntu 22.04. However, any Linux distro equipped with the GUI can use the same process:
First, go to the system “Settings”:
Scroll down the left menu of “Settings” and click on “Users”:
Select the User you want to change the password and before doing so make sure that you have unlocked the settings by clicking on the “Unlock..” button on the top:
Enter the current user password to proceed further:
Change the password and close the menu:
The password has been set for the specified user.
That’s all from this post!
To change the users’ password in Linux, use the commands passwd or chpasswd in the terminal or open the “Users” option in Settings using the GUI method. If the “username” is specified then the password of that respective user will be changed. Moreover, if no “username” is provided then the current user password will be changed. This blog help readers understand the methods of changing or updating the passwords of Linux users.