passwd
command is used to change passwords and provides information about Linux accounts. Normal or root user can change passwords. Normal users can only change their own password on the other hand root can change all user’s passwords. Passwords related information is stored in /etc/passwd
file. The only password which is stored as the hash is stored in /etc/shadow
.
User Password File
As stated previously user account related information is stored in /etc/passwd
. There is information like
- username
- password which is X refers to the
/etc/shadow
file - User ID
- Group ID
- User ID information
- Home directory
- Command or shell
Here is an example passwd
file.
$ cat /etc/passwd

Change Current User Password
We will start by simply changing the current user password. We do not need to provide any user name because the currently logged in user will be used.
$ passwd

Before entering a new password we should provide a current password. The new password should be different than the existing one.
Change Specified User Password
We can change different users than current users. We will specify the user name we want to change the password. We should have root privileges. We will run commands with sudo for root privilege. In this example, we will change the user ismail
password.
$ sudo passwd ismail
Show Specified User Password Status
Password status is used to show current account password expire or validity dates. We will use -S
option with the user name like below.
$ passwd -S ismail

Show All Users Password Status
In the previous example, we have only shown the given user account or password status. We have the chance to list all users. But we need root
privileges again. We will use -l
with -S
like below.
$ sudo passwd -a -S

Lock Specified User Account and Password
If we need to stop users from logging by locking the account. We will provide the account name with the -l
option. In this example, we will lock the account named john
.
$ sudo passwd -l john
Unlock Specified User Account and Password
Locking user accounts is a security measure useful if the user will not use it for a period of time the system. For example, a user will do a holiday for two months and the account should be locked for this period of time. We can also unlock the account with the -u
option like below.
$ sudo passwd -u john
Delete or Make Empty User Password
We can make the user password empty. This will disable the password for the given user account. We will use -d option with the username. In this example, we will disable password for user john
.
$ sudo passwd -d john
3 thoughts on “How To Change User Password with passwd Command In Linux?”