FUNDAMENTALS A Complete Guide for Beginners
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]
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.
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.
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.
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.
Similar Readings
- The “time” Command in Linux [4 Practical Examples]
- The “tty” Command in Linux [4 Practical Examples]
- The “uptime” Command in Linux [5 Practical Examples]
- The “vmstat” Command in Linux [6 Practical Examples]
- The “uname” Command in Linux [11 Practical Examples]
- The “apt-get” Command in Linux [10 Practical Examples]
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.
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.
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.
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.
Similar Readings
- The “free” Command in Linux [8 Practical Examples]
- The “getent” Command in Linux [11 Practical Examples]
- The “groupadd” Command in Linux [7 Practical Examples]
- The “addgroup” Command in Linux [7 Practical Examples]
- The “groups” Command in Linux [6 Practical Examples]
- The “firewall-cmd” Command in Linux [7 Practical Examples]
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.
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.
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.
Similar Readings
- The “groupmod” Command in Linux [5+ Practical Examples]
- The “id” Command in Linux [7+ Practical Examples]
- The “service” Command in Linux [6 Practical Examples]
- The “sestatus” Command in Linux [4 Practical Examples]
- The “shutdown” Command in Linux [7 Practical Examples]
- The “finger” Command in Linux [6 Practical Examples]
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.
Similar Readings
- The “dmesg” Command in Linux [7+ Practical Examples]
- The “install” Command in Linux [6+ Practical Examples]
- The “reboot” Command in Linux [3 Practical Examples]
- The “sync” Command in Linux [8 Practical Examples]
- The “chage” Command in Linux [7 Practical Examples]
- The “env ” Command in Linux [9 Practical Examples]
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.
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
- The “sudo” Command in Linux [8 Practical Examples]
- The “df” Command in Linux [11 Practical Examples]
- The “apt” Command in Linux [13+ Practical Examples]
- The “top” Command in Linux [8 Practical Examples]
- The “htop” Command in Linux [7 Practical Examples]
- The “enable” Command in Linux [6 Practical Examples]