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
User Password File
As stated previously user account related information is stored in
/etc/passwd . There is information like
- password which is X refers to the
- User ID
- Group ID
- User ID information
- Home directory
- Command or shell
Here is an example
$ 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.
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
$ 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
-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
$ 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
$ sudo passwd -d john