In this tutorial, we will focus on how you can change a user’s password in Linux. We will delve deeper and see how to force a user to change their password the next time they try logging in. These commands are standard and will work for any Linux distribution.
Let’s jump right in.
Table of Contents
1. Changing your user password
As a regular user in a Linux system, you can only change your password. The root user is the only user that can change the passwords of other users.
The command used for changing users’ password is the
passwd command. It is usually followed by the username of the user whose password you want to change i.e.
# passwd your_username
For example, if you want to change the password of a user jamie, execute
# passwd jamie
You will be prompted to type your current password and later provide the NEW password and confirm it.
When providing a new password , ensure that you use a
UNIQUE password. A strong password should have the following.
- It should have a combination of Uppercase, Lowercase, Numeric and Special characters
- It should have more than 8 Characters
- It should not contain your biometric details such as name, date of birth, place of residence to mention a few.
Passwords are stored in an ecrrypted format in the
2. Changing Linux password for another user
As discussed before, only the root user can change other users’ password. So, you need to log in as the root user to do this.
Once logged in run the command as earlier shown to change a users password
# passwd username
Once again, you will be prompted for the new password and asked to confirm it.
3. Forcing a user to change password at the Next Login
Usually, passwords are not set to expire. But, you can force a user to change their password the next time they log in to the Linux system.
To do this , use the
passwd command with
--expire option followed by the username of the user:
$ passwd --expire jamie
The next time user logs in with their old password, they will be forced to change the password.
That concludes this tutorial on How to change a user’s password in Linux. Your contribution and feedback are most welcome.