Read in 3 minutes
How to Change User Password in Linux
This tutorial will show you how to change a user password in Linux. We will also cover how to force a user to change their password the next time they login. The examples provided in the tutorial should work with any Linux distribution.
To change the password of a user account in Linux you can use the
passwd command. The encrypted users passwords as well as other password related information are stored in the
As a normal user you can only change your own password. The root user and users with sudo privileges can change another user’s password and define how that user password can be used or changed.
When changing the password make you’re using strong and unique password. Having a strong password is the most important thing you can do to secure your account. Often a strong password has at least 16 characters, use at least one uppercase letter, one lowercase letter, one number and one special character.
Change Your Password
To change your user account password run the
passwd command with no options:
You will first be prompted to enter your current current password. If you enter the correct password, then you will be asked to enter and confirm the new password.
Passwords are not shown on the screen when you enter them.
The next time you login to your system, use the new password.
Change Another User’s Password
As we mentioned in the introduction, only the root user and users with sudo accesses can change the password of a another user account. The following example assumes that you are logged in as user with sudo rights.
To change the password of a another user account, run the
passwd command followed by the username of the user.
sudo passwd linuxize
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
You will be prompted for the new password, which you need to enter twice.
Force User to Change Password at Next Login
By default, passwords are set to never expire. If you want to force a user to change their password the next time they login, use the
passwd command with
--expire option followed by the username of the user:
sudo passwd --expire linuxize
The command above will immediately expire a user account’s password.
The next time the user tries to login with the old password with they will be shown a message forcing them to change the password:
WARNING: Your password has expired. You must change your password now and login again! Changing password for linuxize. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Connection to 192.168.121.209 closed.
Once the user sets a new password the connection will be closed.
In this tutorial, you learned how to change user passwords and how to set password expiry.
For more information about the passwd command, visit the Linux passwd man page.