Sometimes you may need to set a user password or reset a password for security purposes, or because they forgot it. In this article, we will look at how to change user password in Linux. We will use the passwd command to change user password. It is available in all Linux distributions so you can use the following steps to change user password in Ubuntu, Debian, Redhat, Fedora, CentOS, SUSE and other Linux flavors.
How To Change User Password in Linux
Here are the steps to change user password in Linux. We will look at how to change your own password, how administrators can change other user passwords, and also how to force users to change their password when they log in the next time.
We will use the passwd utility to change passwords. It stores all encrypted passwords in /etc/shadow file.
Also read : How to Install Fail2ban in Ubuntu
How to Change Your Own User Password
Regular users can easily change their password by running the passwd command
$ passwd
You will see the following prompt where you need to enter and confirm your new password. Please note, none of the passwords that you type(old & new) will be displayed.
Changing password for ubuntu (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
That’s it. Your password will be changed successfully.
Also read : How to find top CPU consuming processes in Linux
How to Change Password for Other Users
If you are an administrator or user with sudo privileges only then you can change password for other users. Here is the command to change password for other users (e.g. ubuntu)
$ passwd ubuntu
OR
$ sudo passwd ubuntu
You will see the following prompt where you need to enter and confirm the new password for that user.
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Also read : How to Open Port in Linux
How to Change group password in Linux
You can also change password for a group (e.g. team123) using the passwd command with -g option, as shown below.
$ sudo passwd -g team123
Also read : How to Create Remote Git Repository
Force Linux Users to Change password on Login
If you want to force a Linux user to change password when they login next time, use –expire or -e option as shown below.
$ sudo passwd --expire ubuntu OR $ sudo passwd -e ubuntu
Now the next time this user tries to log in, they will see the following prompt which requires them to enter new password.
WARNING: Your password has expired. You must change your password now and login again! Changing password for ubuntu. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
As you can see it is very easy to change, set and reset user password in Linux.