Passwords are very important for every Linux user, without which they will be unable to log into their system, or even run certain commands that require privileges. Sometimes you may need to change or reset a user password in Linux, because they have forgotten it or for security purposes. In this article, we will learn how to change user password in Linux. We will use passwd command for this purpose which is present on all Linux systems by default. We will learn how to use passwd utility to manage passwords from command line in Linux.
How To Change User Password in Linux
passwd utility is a versatile command that allows you to easily manage passwords in Linux. It allows you to change passwords of administrators, as well as regular users and even force users to reset their passwords. We will look at each case one by one.
How to Change Your Own Password
Regular Linux users can change their passwords by logging into their Linux account and simply running passwd command.
$ passwd
You will see the following prompts that asks you to enter your current password, as well as your new password twice. You will not be able to view any of the passwords that you type.
Changing password for ubuntu (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Your password will be updated successfully.
How to Change Password for Other Users
By default, every user can change their own password but only admin users or users with sudo privileges can change other users’ password. To change the password of another user, mention that username after passwd command. Here is a sample command to change password of test_user.
$ passwd test_user
Here you will see prompts asking you for new password twice.
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
How to Change Group Password
You can also use passwd command to change a Linux group’s password. You can do this by using -g option followed by name of group. Here is the command to change password of group grp123.
$ passwd -g grp123
Force Password Reset in Linux
You can also use passwd command to force a user to change password when they login the next time, using –expire or -e option, followed by username on whom you want to enforce password reset. Here is an example to change password for username test_user.
$ passwd --expire test_user OR $ passwd -e test_user
Next time the user logs in, they will see the following prompt.
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
passwd command provides many useful options. We will look at a couple of common ones. You can use -S option to check the status of user’s password.
$ passwd -S test_user
If you want to view the password status of all users, use -a option along with the -S option.
$ passwd -a -S
If we wanted to set number of warning days for a specific user, we can do it using -w option. Here is an example to set number of warning days to 7 in Linux.
$ passwd -w 7 test_user
In this article, we have learnt several different ways to change user password in Linux using passwd command.
Also read:
How to Find Top CPU Consuming Processes in Linux
How to Install Fail2ban in Ubuntu
How to Open Port in Linux
How to Create Remote Git Repository
How to Enable Keep Alive in NGINX
Related posts:
Sreeram Sreenivasan is the Founder of Techosha. He has helped many Fortune 500 companies in the areas of BI & software development. He has more than 10 years of experience in web development, Python, Linux, SQL and database programming.