passwd ‐ #security #users - five4nets/Linux-Knowledgebase GitHub Wiki

🔐 Linux passwd Command Tutorial

The passwd command in Linux is used to change user account passwords and manage password policies. It's a vital tool for both users and system administrators to maintain system security.


🧰 Basic Syntax

passwd [OPTIONS] [USERNAME]
  • USERNAME: The target user account. If omitted, it defaults to the current user.
  • OPTIONS: Flags to modify behavior (e.g., lock, expire, status).

🔧 Common Options

Option Description
-d Delete a user's password (makes account passwordless)
-e Expire a password immediately (forces change at next login)
-l Lock a user account
-u Unlock a user account
-S Show password status
-n Set minimum days between password changes
-x Set maximum days a password is valid
-w Set warning days before password expiration
-i Set days of inactivity after password expiration
-a Show status for all users (used with -S)

🧪 Examples

1. Change Your Own Password

passwd

2. Change Another User's Password (as root)

sudo passwd username

3. Lock a User Account

sudo passwd -l username

4. Unlock a User Account

sudo passwd -u username

5. Expire a Password Immediately

sudo passwd -e username

6. Delete a User's Password

sudo passwd -d username

7. View Password Status

passwd -S username

8. Set Password Expiry Policy

sudo passwd -n 1 -x 90 -w 7 username

This sets:

  • Minimum days between changes: 1
  • Maximum password age: 90 days
  • Warning period: 7 days

🧠 Notes

  • Passwords are stored in encrypted form in /etc/shadow.
  • When typing passwords, no characters are shown for security.
  • Locked accounts cannot be accessed via password but may still allow SSH key login.

📚 References


Happy securing! 🔐


Let me know if you'd like a version that includes password aging policies or integrates with `chage` for advanced control.