Table of Contents
How to Manage User Passwords from Terminal in Linux is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.
Like many things on Linux, passwords are easily managed directly from the command line. The passwd utility is designed to allow you to quickly and easily access all password-related commands on the system. You can use it to change and manage your password and other user passwords on the system. In addition, you can use it to turn off password authentication for a specific user, lock user accounts and set the required password expiration time to keep the system safe. You will show you how to use the passwd utility to manage passwords in Linux.
Change the password
First, the simplest job you can do with the passwd utility is to change your password with the passwd command only.
passwd

It will ask you to provide your current password followed by your new password.
Change the password of another user
With root or sudo, you can also change someone else's password. You only need to provide the account username you want to change for passwd.
sudo passwd username
Note : Usename is the username

With this command, you do not need to provide the current password. It only requires you to set up a new password.
Lock user account password
You can easily lock a user's account by locking their password. This will prevent them from logging in with a password. Other methods, like SSH keys, will still work. To lock an account, you will need sudo and -l flag.
sudo passwd -l username
You can also unlock your account with the -u flag.
sudo passwd -u username
Lock root permissions
If for security reasons, you want to block all access to the root account, so that sudo is the only way to manage the system, you can do that with the following command:
sudo passwd -l root
It works similarly to other users.
Do not use a password
You can also choose to set up user accounts without a password. But this is not a good idea for security, but you can avoid a lot of trouble like having a multimedia computer that you don't need to be secure that way. To do this, use passwd with a simple flag to delete the user password.
sudo passwd -d username
Set a time limit for user passwords
Setting a password deadline is quite common. This is a good security measure, preventing old users' passwords from entering the system. If you are running a business-based system, it is difficult to control their passwords and whether they will enter the system. Requiring them to change passwords after a certain period of time will force users to refresh their passwords and reduce the risk of violations.

Use the -x flag followed by the number of days you want the user password to be valid.
sudo passwd -x 30 usernames
The above command sets the time when the user password will expire after 30 days.

You can also set up a system to alert users that their password is about to expire. Use the -w flag with the number of days before it expires to automatically alert users to change their password.
sudo passwd -w 5 username
If you know there is a problem with the user's password, you can automatically make their password expire. This will force them to set a new password immediately.
sudo passwd -e username
- Secure passwords on UNIX and LINUX networks
- 10 ways to generate random passwords in Linux from the command line
- Turn off the Password Lock screen in Ubuntu
FAQ
What should you know about change the password?
First, the simplest job you can do with the passwd utility is to change your password with the passwd command only.
What should you know about change the password of another user?
With root or sudo, you can also change someone else's password. You only need to provide the account username you want to change for passwd.
What should you know about lock user account password?
You can easily lock a user's account by locking their password. This will prevent them from logging in with a password. Other methods, like SSH keys, will still work. To lock an account, you will need sudo and -l flag.
Reader Comments 0
Sign in with email or Google to join the discussion.