passwd — change or lock a password
The passwd command changes your own password; as root it sets, locks and shows the passwords of other users.
Cheat sheet
9 commands Printable version-
passwdchange your own password -
sudo passwd aliceset someone's password, no old one needed -
sudo passwd -S alicepassword status -
sudo passwd -l alicelock password login -
sudo passwd -u aliceunlock -
sudo passwd -e aliceforce a change at next login -
sudo passwd -d alicedelete the password (login without one!) -
sudo passwd -x 90 -w 7 alicemax age 90 days, warn 7 days ahead -
echo 'alice:NewPass-2026' | sudo chpasswdfrom a script
Overview
passwd changes an account's password. A regular user changes only their own and
types the current one first. Root (through sudo) sets anyone's password without
the old one:
Password characters aren't shown while you type — no letters, no asterisks. That's expected: type it and press Enter.
The password itself isn't stored anywhere: /etc/shadow holds its hash (on Ubuntu
24.04 the string starts with $y$, the yescrypt algorithm). Only root can read
/etc/shadow.
-S shows the password state:
Fields: name; P — password set, L — locked, NP — no password; date of the last
change; min and max age in days; days of warning before expiry; days after expiry
until the account is disabled (-1 — not set).
Options
8chage shows password ages in more detail (chage -l alice). Full list of options —
man passwd.
| Option | What it does | Example |
|---|---|---|
-S --status |
Password status — P set, L locked, NP none; dates and ages. | sudo passwd -S alice |
-l --lock |
Lock password login. SSH key login still works. | sudo passwd -l alice |
-u --unlock |
Unlock the password. | sudo passwd -u alice |
-e --expire |
Force a password change at the next login. | sudo passwd -e alice |
-d --delete |
Delete the password — the account is left with an empty one. dangerous | sudo passwd -d alice |
-x --maxdays days |
Maximum password age in days. | sudo passwd -x 90 alice |
-w --warndays days |
Days of warning before the password expires. | sudo passwd -w 7 alice |
-a --all |
With -S — the status of every account's password. | sudo passwd -S -a |
Nothing found. Try a shorter query.
Recipes
3Block login without deleting the account
passwd -l closes only password login: an SSH key keeps working. To close login
completely you also need nologin or chage -E 0.
Passwords for several users at once
chpasswd reads name:password pairs. Don't leave such lines in the shell history or
in files: they're passwords in plain text.
Troubleshooting
5passwd: Authentication token manipulation error
passwd couldn't change the password. Causes by frequency: the current password was
mistyped; the two entries of the new one didn't match (the line above says Sorry,
passwords do not match.); the new password failed the checks — too short, too simple
or too close to the old one. If root gets it and the password is clearly fine, check
that the root filesystem isn't mounted read-only (findmnt /) and has free space
(df -h /).
passwd: password unchanged
The closing line after any such failure. The line above it names the cause.
passwd: You may not view or modify password information
A regular user is trying to see or change someone else's password. Root is needed:
sudo passwd -S alice.
The user still logs in after passwd -l
They log in with an SSH key: locking the password doesn't touch keys. Close login with
sudo usermod -s /usr/sbin/nologin alice or sudo chage -E 0 alice.
I type the password and nothing appears
That's by design: the password isn't echoed. Type it fully and press Enter; if you lose track, Ctrl+U erases what you've typed.
Danger zone
2passwd -d opens login without a password
After passwd -d the account has an empty password, and depending on PAM and SSH
settings anyone can log in without typing anything. To forbid a password, use passwd
-l, not -d.
The root password
sudo passwd root enables password login as root: on Ubuntu it's off by default, and
administration goes through sudo. Don't turn it on without a reason.
See also
Found an inaccuracy? Report an error in the article