This tutorial describe how to change user password in Linux. We will also cover how to change or set password of another users using sudo privileges.
You can use
passwd command to change user password in Linux distribution. Password related information are stored at
/etc/shadow file. If you are a normal user in your system then you can only change password of your own account. Only root account or users with
sudo privileges can change password of another users.
Change Your User Password
To change password of your own user account open terminal and run following command without any options:
It will prompt you to enter current password. Once it will be authenticate successfully you will be asked to enter new password and confirm password.
At next login you can use your new password instead of old one.
Change Another User’s Password
As we mentioned above that only root or sudo users can change another user’s account password. Following is the basic syntax to change another user’s password.
sudo passwd [username]
For example, assumes that you are logged in as a user with
Now to change another user’s account password run the
passwd command followed by the username. Here we want to change the password for
demouser then run the following command:
sudo passwd demouser
You will be prompted to enter and confirm the new password:
Output Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Force User to Change Password at Next Login
If you want to force users to change their account password at next login then you can it by adding expiry option. By default, passwords are set to never expire. Pass the
--expiry option along with
passwd command as given below:
sudo passwd --expiry demouser
This command will immediately expire a user account’s password.
demouser will try to login next time using old password it will force to set new password as given below:
WARNING: Your password has expired. You must change your password now and login again! Changing password for demouser. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Connection to 192.168.43.125 closed.
After that once the user sets a new password the connection will be closed
Change Group Password
You can change password of group using
-g option with
passwd command. For example, to change the password of group sales run following command.
sudo passwd -g sales
In this guide, you have learned how to change own and another user account passwords. It’s recommended that to change your password frequently and use a unique password for each account for security purpose. Get more information about the passwd command at the Linux passwd man page.