The “passwd” Command in Linux [7 Practical Examples]

The passwd command in Linux is used for changing user passwords. The word passwd is used as a short form of Password. This command is very useful for handling user Id properly. In this article, I will explain in detail how to use the passwd command. And I will also show you some practical examples.

A. Description

The passwd command in Linux helps a normal user to change their own user password. But a normal user cannot change all the passwords on a system. Only the superuser can change all the passwords. Because the superuser has root permission. Follow me step by step to know all about permission.

B. Syntax

The syntax for the passwd command is very simple. It’s just the passwd command followed by an option and a user name. The syntax is given below.

passwd [OPTIONS] [USER]
Note: In the above syntax OPTION is enclosed by a square bracket. Anything inside the square bracket is not mandatory. Then the USER you want to change the password of.

C. Options

Many useful options are available for the passwd command. I have listed some of the most used ones here. However, if you want to know more about options for the passwd command you can always check the man page for the passwd command.

man passwd

Useful Options

  • -a, –all: Shows status of all users.
  • -d, –delete: Deletes user password. The user account becomes unprotected.
  • -h, –help: Display help message and exit.
  • -e, –expire: Immediately makes the user password.
  • -i, –interactive: Make an account inactive after password expiration.
Note: The options in Linux CLI (Command Line Interface) are all case-sensitive. So, be cautious while using them. Options starting with (–) are long forms of options. Long Forms have the same meaning as Short Forms.

Practical Examples of the “passwd” Command in Linux

The passwd command is very easy to use. It is one of the most important commands of the Linux CLI. I have two user accounts akash and tom on my system which you can see from the picture below.

Showing current user accounts

Here I have given some basic examples of the passwd command.

Example 1: Changing User Password Using the “passwd” Command in Linux

If you want to change your user password you have to be inside your own user account. You can change your user password from outside your own account but you have to be the superuser then. I will show you how to do that in later Examples. In this example, you will learn how to change the user password within the account. Now I am in my user id akash which you can see in the picture below.

Showing current user id

So, I will show you how to change the password of this account from this user id. Now follow the steps below to change your password.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

passwd akash

➌ Now, press the ENTER button.

➍ Type in the current password.

➎ Now, press the ENTER button.

➏ Type in the new password.

➐ Now, press the ENTER button.

➑ Retype the new password.

➒ Now, press the ENTER button.

Output >

As you can see from the picture below that the password has been updated.

changing passwd using the passwd command in linux


Similar Readings


Example 2: Changing User Password without Providing Username

The passwd command can work even if you don’t specify any user name. In this case, the command just assumes that you want to change the user password of the user account you are currently in. now I am still in my user account akash which you can see below.

Showing current user id

Now I will change the password for this account without telling the command the user name. Now follow the steps below to know how this works.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

passwd

➌ Now, press the ENTER button.

➍ Type in the current password.

➎ Now, press the ENTER button.

➏ Type in the new password.

➐ Now, press the ENTER button.

➑ Retype the new password.

➒ Now, press the ENTER button.

Output >

As you can see from the picture below that the password has been updated. And you can also see that I didn’t specify any user inside the command.

using passwd command in linux to change password

Example 3: Changing User Password of Other User Account Using the “passwd” Command in Linux

If you want to change a user password other than yours you can’t do that. Because you are not the superuser. If you look at the picture below you can see that I tried to change the user password of account tom. But I was denied that because I am not a superuser.

trying to change password using the passwd command in linux

Now follow the steps below to see how you can change your password as a superuser.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo passwd tom

➌ Now, press the ENTER button.

➍ Type in the current user password.

➎ Now, press the ENTER button.

➏ Type in the new password for tom.

➐ Now, press the ENTER button.

➑ Retype the new password.

➒ Now, press the ENTER button.

Output >

As you can see from the picture below that the password has been updated.

changed password using the passwd command in linux

Note: The sudo command enables the user to be a superuser.

Similar Readings


Example 4: Deleting User Password Using the “passwd” Command in Linux

If you want to delete the user password for your account immediately, you have to use the passwd command in Linux with an Option. That option is (-d). But you have to be the root user. As you can see from the picture below I couldn’t delete my user password because I am not a root user.

trying to delete my password

This means I will have to use the sudo command. Now follow the steps below to see how this works.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo passwd -d akash

➌ Now, press the ENTER button.

➍ Type in the current user password.

➎ Now, press the ENTER button.

Output >

As you can see from the picture below that the password has been updated.

changed password using the passwd command in linux

Note: The sudo command enables the user to be a superuser.

Example 5: Viewing User Password Information Using the “passwd” Command in Linux

If you want to view your current user password information, you have to use an option. You have to use the (-S) option. I have deleted the user password of akash. So if I use the (-S) option it will show me that No Password is available for user akash. Now follow the steps below.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo passwd -S akash

➌ Now, press the ENTER button.

Output >

As you can see from the picture below that the info says No Password.

showing password information

Note: The sudo command enables the user to be a superuser.

Similar Readings


Example 6: Viewing All User’s Password Information Using the “passwd” Command in Linux

If you want to view your current user password information, you have to use an option. You have to use the (-S) option along with option (-a). Now follow the steps below to see how this works.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo passwd -S -a

➌ Now, press the ENTER button.

Output >

As you can see from the picture below that the info for all the users is printed on the terminal screen.

Viewing all user password

Note: The sudo command enables the user to be a superuser.

Similar Readings


Example 7: Making User Password Expired Using the “passwd” Command in Linux

If you want to make your user password expired, use the passwd command with the (-e) option. Now follow the steps below to see how this works.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo passwd -e akash

➌ Now, press the ENTER button.

➍ Now type in your current password.

➎ Now, press the ENTER button.

Output >

As you can see from the picture below that the password expiration was successful.

using the passwd command in linux

Note: The sudo command enables the user to be a superuser.

Conclusion

In this article, I have tried to show you how the passwd command works. And I have also included some useful examples. If you go through this article properly, you should be able to use the command passwd properly on your own.


Similar Readings

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Md. Rafsan Zani

Hello, I’m Md. Rafsan Zani. I have recently completed my Undergraduate from the Bangladesh University of Engineering and Technology (BUET). Currently, I’m pursuing higher studies abroad. I’m really interested in computer science and would like to learn a lot about the wonderful world of computers. Currently, I’m working as a Linux Content Developer Executive and find Linux really interesting. I certainly would like to learn more about Linux and implement them in my future studies. Read Full Bio

Leave a Comment