Beginner’s Guide to the Linux passwd Command: 8 Practical Examples

As a Linux command line user, it’s crucial to be familiar with utilities that assist in managing user accounts. One such essential tool is passwd, which allows you to change your account password. This tutorial will cover the fundamentals of this command using simple, straightforward examples.

Before diving in, please note that all examples in this tutorial have been tested on an Ubuntu 16.04 LTS machine.

Linux passwd Command

The passwd command enables users to update their account passwords. Its syntax is as follows:

passwd [options] [LOGIN]

According to the man page, the command functions like this:

The passwd command modifies passwords for user accounts. A typical user may only change the password for their own account, while the superuser has the capability to change passwords for any account. It also handles the account or password validity period.

The following examples, structured in a question-and-answer format, will provide a deeper understanding of how this command works.

Q1. How to Use the passwd Command?

Basic usage is straightforward. Simply execute the passwd command without any additional options or input.

passwd

Here’s some crucial information regarding the operation of passwd:

The user is initially prompted for their existing password, if one exists. This password is encrypted and checked against the stored password. Only one attempt is granted for correctness. Superusers can bypass this to reset forgotten passwords.

After inputting the password, system checks determine if the user is permitted to change the password at the current time. If denied, passwd exits.

The user is prompted twice for a new password, ensuring both entries match before proceeding.

Passwords are evaluated for complexity, generally requiring 6 to 8 characters, including elements from:
  
  • lower case letters
  
  • digits 0 through 9
  
  • punctuation marks 
  
It's critical to avoid system default erase or kill characters. Non-compliant passwords are rejected for insufficient complexity.

For example, here’s how I changed my password:

Note: If you have superuser privileges or are a system admin, you can change any account’s password by specifying the account’s username. For example:

passwd himanshu

Q2. How to Remove a Password from an Account?

The passwd command can remove a password from a user account using the -d option.

passwd -d

This action effectively disables the password, rendering the account password-less.

Q3. How to Force Password Expiry?

System admins may require users to change passwords immediately. The -e option forces the password to expire, prompting a change at the next login.

passwd -e

Q4. How to Disable an Account if the Password Remains Expired?

If a user fails to update an expired password, the account can be disabled after a predefined period using the -i option, requiring a numerical input for the duration in days.

passwd -i 5

This command disables the account if the password remains expired for 5 days.

Q5. How to Set a Minimum Time Interval Between Password Changes?

The passwd command allows setting a minimum time interval between password updates using the -n option, which takes a numeric input representing days.

passwd -n 10

This command ensures a 10-day gap between password changes. A value of 0 allows password updates anytime.

Q6. How to Display Account Status Information?

Use the -S option with passwd to display account status:

The status information consists of 7 fields, starting with the login name. The second field shows password status: locked (L), no password (NP), or usable password (P). The third field is the last password change date, followed by minimum, maximum age, warning, and inactivity periods in days.

Q7. How to Set Password Validity Period?

Using the -x option, passwd can define a password’s maximum validity in days.

passwd -x 100

Q8. How to Warn Users of Upcoming Password Expiration?

The -w option lets passwd warn users a specified number of days before password expiration.

passwd -w 7

Conclusion

The passwd command is an invaluable tool every Linux user, whether a beginner or an expert, should understand. This tutorial covered essential features of passwd. To deepen your knowledge, practice these commands and refer to the man page for further details.

FAQ

Q. Can I use passwd to change passwords for others?
A. Yes, if you have superuser privileges, you can modify passwords for other accounts.

Q. Is it possible to revert to a disabled account?
A. Yes, you can enable an account by resetting a password or modifying account status.

Q. Why should I use passwd instead of other tools?
A. Passwd is a standard Linux utility, adhering to system security and compatibility standards.

Q. What are some alternatives to passwd?
A. Other tools include chpasswd, usermod, and graphical utilities available on some Linux distributions.