What is the passwd command in Linux?

The passwd command in Linux.

The passwd is a command in Linux and Unix-like operating systems. This command is useful to change the user login password.

If you want to change any user account password then you must have root user account level permission or sudo level privilege.

But if you are a regular user and you want to change the password of your account only then you can change it without any privilege because by default every user has this permission to change the password of his/her account.

How to get help for the passwd command

I always suggest reading the manual page and help. So, It will give you an in-depth introduction to the command.

So, to get the manual page type the below command,

man passwd

But, to get the only command options, you can type the below command.

passwd --help

Syntax of the passwd command

Now you know how to get help about the passwd command. So, let’s talk about passwd syntax. The syntax of the passwd command is as below,

Syntax: passwd [options] [username]

Let’s discuss passwd command in Linux.

A useful note (A small story)

I have seen many times one common problem that a system admin face. He has been logged in with the root user, and he is trying to change the password for a user. What did he do, he types passwd and hit enter and then start changing the password and still did not understand, and he gave the password to the user. But guess what happened the user is not able to login with the new password.

The user comes back again and tells the problem to the same system admin that I’m not able to log in. The system admin did the same thing again. The same problem, the user is standing on the head of the system admin.

This time he came to me and asked, “Sahil sir, I’m changing the password for Ram, but it is not working. I don’t know what happened?” I said, let me check, and I typed on command prompt passwd ram and hit enter, suddenly he realized and said, “Oh! Sahil sir, I was not putting the user name after passwd. that’s why.” I said, “congratulations, you recognized the problem.”

So always make sure for whom you are trying to change the password. If you are changing for the user you have logged in then it’s not necessary to put the name after passwd but if you are changing for someone else then put the user name. And this is a good practice to put always user name after passwd.

Changing a user password

Here, I am going to change the password for the user ram and I have been logged in as root user, If you are a sudo user then put sudo before the command passwd.

If you are going to change for anyone then put the name of that person instead of ram.

passwd ram

As a result, you can see the output in the below picture.

passwd command in linux
Changing the password for user ram

For sudo user, the command will look like the below command,

sudo passwd ram

Stopping the user to login into his/her account using the passwd command

Sometimes, you want to stop someone from login to his/her user account. You can accomplish this task in many ways, but you can also use the passwd command. What it does, it locks the user password. If you want to use it, then you can use the below syntax and example to understand that. And you can block any user account password.

passwd -l username

For example, I’m going to block a user account password whose name is the ram. So the command to block the user’s account password will look like the below and also you can see that use on command prompt through the below picture.

passwd -l ram
passwd command in linux
Locking user account password using the passwd command

In the picture, you can also see that in the password file which is located in /etc/passwd, there are two exclamation marks (!!) just before the encrypted password which indicating that the user account password has been locked. And When the user tries to log in to his/her account, he/she will get the message that Authentication failure.

Unlocking the user account password with the passwd command

Now we are going to unlock the user account password. Here, we’ll only change the argument -l to -u. As we have already locked user ram so now, it’s time to unlock him. And I will also demonstrate in the picture with the example user ram. See the below syntax.

passwd -u username

For example,

passwd -u ram

As a result, you can see in the below picture.

Unlocking the user ram with the passwd command

As you can see in the above picture, the two exclamations (!!) are no more there. The user has been unlocked. I told you this -l and -u argument because this is handy sometimes. Very useful.

** I would like to share with you one more very nice argument of passwd command. So let’s see that below.

Checking the status of the user with the passwd command

This is another useful argument while using passwd.

passwd -S username

For example,

passwd -S ram
passwd -S
Getting status details through the passwd command

As you can see in the picture, when I typed passwd -S ram, then I get the account password related information. And It gives me a total of seven fields. In which every filed has there own meaning. You can get more details about every field below.

  • The first field indicates, user name.
  • The second field shows that if it is L, this means the user account password has been locked. If it is NP, It means there is no password for that user. If it is P, it means the user has the right password.
  • The third field shows the last date of password change.
  • The fourth field shows the minimum age of the password.
  • The fifth field shows the maximum age of the password.
  • The sixth field shows the warning period, and the seventh filed shows the inactivity period for the password. This information is in days.

So This was the only main important information about passwd command. If this information is useful for you, then that’s great. thank you for visiting this page. You can share this article with your friends. You can also read information about the passwd file, By clicking on the link What is /etc/passwd file

Conclusion

In this article, you learned about the passwd command in Linux with fundamental arguments. And you can see that it is not robust. I hope, you understand, but if you have any questions, you can ask in the comment section.

Also, you may like to read about

One comment

Leave a Reply

Your email address will not be published.

  1. This is very nicely explained. Thanks guruji.