Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

passwd Command Guide for Changing User Passwords

passwd changes the password for a user account — your own when run bare, or another user’s when run with sudo.


What is passwd, and Why Use It?

Every account defined in /etc/passwd has a password (or a marker saying it doesn’t). passwd is the tool for setting and changing those passwords: expired-password rotations, first-time setup of a new account, and the occasional “I locked myself out of the deploy user”.

Run with no arguments, it changes your own password. Run with sudo, it changes someone else’s.

passwd

Why Learn passwd?

  • It’s mandatory knowledge for account setup — every new user created with useradd needs a password before they can log in.
  • It’s part of routine hygiene — password expiry policies (chage) and rotations are built around it.
  • It explains the locked/! entries you’ll see in system account files — passwd is how those markers get set and cleared.
  • It’s the recovery path — when an account’s password is forgotten or expired, sudo passwd is the fix.

Passwords are the oldest and simplest form of authentication, and passwd is where they live. Knowing it means you can always restore access — to your own account, or (with sudo) to any account on a system you administer.


1. Change Your Own Password

passwd

Example:

$ passwd
Changing password for alice.
Current password:
New password:
Retype new password:
passwd: password updated successfully
  • You must enter your current password first, then the new one twice.
  • Modern systems enforce strength rules (length, complexity) and will refuse weak choices.
  • Your password is stored hashed in /etc/shadow, not in /etc/passwd — see the concept page.

2. Change Another User’s Password

With sudo, passwd targets any account:

sudo passwd username

Example:

# Reset the deploy account's password
$ sudo passwd deploy
New password:
Retype new password:
passwd: password updated successfully

# As root, no password prompt for the target at all
$ sudo su -
# passwd bob
New password:
Retype new password:
  • sudo passwd skips the “current password” step for the target user — which is exactly the recovery power it provides.
  • Only users with sudo rights (or root) can do this; regular users can only change their own.
  • This is the standard way to restore access to an account whose owner forgot the password.

3. Lock and Unlock an Account

passwd can disable or re-enable a password without deleting the account:

sudo passwd -l username   # lock
sudo passwd -u username   # unlock

Example:

# Lock the guest account
$ sudo passwd -l guest
passwd: password expiry information changed.

# Check the state
$ sudo passwd -S guest
guest L 12/04/2026 0 99999 7 -1
  • -l prefixes the stored hash with !, so no password can match — password login stops working.
  • -S shows status: P (usable password), L (locked), NP (no password).
  • Locking is safer than deleting when you might need the account (and its files) later.

4. Check Password Expiry

Expiry policies are set and viewed with passwd’s companions:

sudo chage -l username    # full expiry report
sudo passwd -x 90 username   # max 90 days between changes

Example:

$ sudo chage -l deploy
Minimum password age: 0 days
Maximum password age: 90 days
Password expires:     Mar  4, 2027
Password inactive:    never
Account expires:      never
  • Service accounts often have expiry disabled (max age -1) so automated logins never break.
  • Human accounts on shared systems are usually given a maximum age to force rotation.
  • chage is the reporting tool; passwd and passwd -x are the setters.

5. What Actually Changes: /etc/passwd vs /etc/shadow

The name passwd is historical — passwords no longer live in the file of that name:

# The account database (no passwords here)
grep alice /etc/passwd
alice:x:1000:1000:Alice,,/home/alice:/bin/bash
#            ^ the x means "look elsewhere"

# The real password store (root-only readable)
sudo grep alice /etc/shadow
alice:$y$j9T$Qz...:...:19700:0:99999:7::
  • /etc/passwd is world-readable and holds account metadata only — the x is a pointer.
  • /etc/shadow holds the actual hash and is readable only by root.
  • passwd writes to shadow; that’s why changing your password doesn’t require root, but reading the hashes does.

Common Pitfalls

  • Looking for the new password in /etc/passwd. It’s in /etc/shadow (hashed); the x in passwd just says “hashed elsewhere”.
  • Forgetting sudo when changing someone else’s password. passwd bob as a normal user fails — it only changes your password unless you’re root.
  • Typo-ing a new password with no way back. passwd asks you to retype; if the two don’t match, nothing changes — but there’s no “undo”, so type carefully.
  • Locking an account you still need. passwd -l blocks password login; if that account is used by a service or cron, you may break it. Check dependencies first.
  • Setting expiry on service accounts. A 90-day max age on an automated account means a silent failure when it expires. Humans rotate; services usually don’t.
  • Assuming passwd changes SSH keys. It doesn’t — key-based login is separate; see the SSH Commands page.

PageWhy it’s related
useraddCreates the accounts whose passwords you then set
/etc/passwdThe account file passwd’s name points at (historically)
suSwitching to an account needs the password you just set
sudoThe elevation that lets you change other users’ passwords
idVerifying which account you’re changing passwords for
SSH CommandsKey-based login, an alternative to passwords

passwd Cheatsheet

CommandMeaning
passwdChange your own password
sudo passwd usernameChange another user’s password
sudo passwd -l usernameLock an account (block password login)
sudo passwd -u usernameUnlock a locked account
sudo passwd -S usernameShow password status (P/L/NP)
sudo passwd -x 90 userSet maximum password age to 90 days
sudo chage -l usernameFull password expiry report
passwd -k(Kerberos only) renew token — rare on Linux