How to use the passwd command on Ubuntu Linux with examples

|

|

The post instructs new Linux users, particularly those using the Ubuntu Linux OS, on the passwd command usage. The passwd command alters user account passwords via the command line. The post explains the syntax, gives various options that influence command behavior, and provides examples for changing passwords, locking accounts, checking account statuses, and forcing password…

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

The passwd command is used on Ubuntu Linux to change user account passwords. It is a command-line tool that allows users to change their passwords or other users’ passwords on the system.

It is an essential command for system administrators who manage user accounts on Ubuntu Linux. The passwd command can also be used to set password policies, expire passwords, and lock user accounts.

Using the passwd command, users can update their account security and ensure their accounts are protected from unauthorized access.

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.

An average user may only change the password for their account, while the superuser may change the password for any account.

Syntax:

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.

Options:

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.The -e or –expire option immediately expires an account’s password. This, in effect, can force a user to change
their password at the user’s next login
-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 -u or –unlocks the password of the named account.
 -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.

Examples:

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.

passwd

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 the change of 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 John’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]

Options:
  -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!

Like this:



One response to “How to use the passwd command on Ubuntu Linux with examples”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.