How to use passwd command on Ubuntu Linux with examples

The passwd command changes passwords for user accounts.

This post shows new users and students what the passwd command is for and how to use it.

If you’re a new user or student learning to use Linux, the easiest place to start might be on Ubuntu Linux OS.

Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.

However, when you’re learning to use and understand Ubuntu Linux, you’ll also want to learn the commands behind the graphics and mouse-clicking. And how to use them. This tutorial is going to show you how.

When you’re ready to learn how to use the passwd commands, follow the guide below:

About the passwd command:

The passwd command changes passwords for user accounts, like using your mouse and keyboard to change your password for your account or another. The passwd is the way to do it on the command line.

A normal user may only change the password for his/her account, while the superuser may change the password for any account.


The syntax is the rule and format of how the passwd command can be used. The syntax can be reordered. But a straight format must be followed.,.

Below is an example syntax of how to use the passwd command.

passwd [OPTION]. LOGIN.


The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the command. They are separated by spaces and followed after the command options.

Below are some options for the passwd command:

LOGIN.Replace LOGIN .. with the name of the account you want to change the password. If the account doesn’t exist, the command will fail and not execute.
-a, –all,
The -a or –all option can be used only with -S and causes show status for all users. If you want to see the status of all the accounts on the system, use this option.
-d, —  delete           The -d or –delete option deletes a user’s password (make it empty). This is a quick way to disable a password
for an account. In addition, it will set the named account passwordless.
-e, –expireThe -e or –expire option immediately expires an account’s password. This, in effect, can force a user to change
his/her password at the user’s next login
 -u, –unlockThe -u or –unlock the password of the named account.
-i, –inactive INACTIVEThe -I or-inactive option is used to disable an account after the password has expired for several days. After a user account has had an expired password for INACTIVE days,
the user may no longer sign on to the account.
-l, –lock The -l or –lock option locks the password of the named account.
-x, –maxdays MAX_DAYS The -x or –max days set the maximum number of days a password remains valid. After MAX_DAYS, the password is required to be changed.
-h, –help Display help message and exit.
-w, –warm days WARN_DAYS Set the number of days of warning before a password change is required. The WARN_DAYS
option is the number of days before the password expires that a user will be warned
that his/her password is about to expire.


Below are some examples of how to run and use the passwd on Ubuntu Linux.

If you want to change your account password, just run the below command. The passwd without the login name will default to the user account running. Then, it prompts you to change the account password.


If you wish to change John’s account password, run the passwd command and specify John’s account name. in this case, it’s called John.

sudo passwd john

The commands above prompt to change the password for John’s account.

If you’re not logged in as a root account, you may have to use the sudo command.

sudo passwd john

To lock John’s account, run the commands below.

sudo passwd -l john

To check John’s account status, run the command below

sudo passwd -S -a john

To immediately expire Johns’s’s password, run the commands below. John will be required to change his password at the next login.

sudo passwd -e john

When you run passwd with the –help option, you’ll see the help text below:

Usage: passwd [options] [LOGIN]

  -a, --all                     report password status on all accounts
  -d, --delete                  delete the password for the named account
  -e, --expire                  force expire the password for the named account
  -h, --help                    display this help message and exit
  -k, --keep-tokens             change password only if expired
  -i, --inactive INACTIVE       set password inactive after

That’s it!

I hope you like it, and please come back soon for more Ubuntu Linux commands!