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 used for and how to use it.

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

Ubuntu is an open-source Linux operating systems that runs on desktops, laptops, server 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 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 own 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 systax can options can be reordered. but straight format must be followed.,.

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

passwd [OPTION]. LOGIN.


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

Below are some options of the passwd command:

LOGIN.Replace LOGIN .. with the name of the account you want to change the password. If the account doesn’t already 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 for all the acconts 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. 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 unlocks the password of the named account.
-i, –inactive INACTIVEThe -i or –inactive option is used to disable an account after the password has been expired for a
number of 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 –maxdays sets 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, –warndays WARN_DAYS Set the number of days of warning before a password change is required. The WARN_DAYS
option is the number of days prior to the password expiring 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 own account password, then just run the command below. The passwd without LOGIN name will default to the user account running it prompt 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 it it.

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’ password, run the commands below. John will be required to change his password at the next logon.

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!

Hope you like it and please come back soon for more Ubuntu Linux command!