passwd is the Linux command that changes a user account password and manages related account state such as password aging, locking and forced expiry. Any user can run the passwd command to change their own password, while the root account can set, lock or expire the password of any user on the system.
In Linux permissions, passwd is the classic example of a setuid program: an ordinary user cannot write to /etc/shadow, yet passwd updates it on that user’s behalf because the binary runs with root privileges and enforces its own checks. It is usually provided by the shadow-utils package and integrates with PAM for password quality and authentication rules.
How the passwd command updates credentials
The passwd command works by authenticating the caller, validating the new password and writing a new hash to the shadow database. When a regular user runs it, PAM first asks for the current password, then applies quality modules such as pam_pwquality, and finally the new password is hashed and stored. When root runs passwd alice, the current password prompt is skipped, because root is already authorized to change any account.
Passwords are never stored in clear text. The field in /etc/shadow holds a string such as $6$salt$hash or $y$..., where the prefix identifies the hashing algorithm. Modern distributions default to yescrypt or SHA-512 crypt, both of which use a random salt and many iterations to slow down offline guessing. The following table shows how the files involved are protected.
| File | Contents | Typical mode | Readable by |
|---|---|---|---|
| /etc/passwd | Account names, UIDs, shells | 0644 | All users |
| /etc/shadow | Password hashes and aging fields | 0640 or 0000 | Root and the shadow group |
| /usr/bin/passwd | The program itself | 4755 | All users, runs as root |
| /etc/pam.d/passwd | PAM stack for password changes | 0644 | All users |
The 4 in mode 4755 is the setuid bit. It makes the kernel set the effective UID of the process to the owner of the file, which is root, so the program can update the shadow file. The program itself then restricts ordinary users to changing only their own entry.
Important passwd options
Beyond changing a password, passwd exposes account administration options that mostly require root. Option names are consistent across shadow-utils based distributions, although some variants differ slightly in output format.
| Option | Effect | Who may use it |
|---|---|---|
-l | Locks the password by prefixing the stored hash | Root |
-u | Unlocks a previously locked password | Root |
-d | Deletes the password, leaving the account passwordless | Root |
-e | Expires the password, forcing a change at next login | Root |
-S | Shows status: locked, set or no password, plus aging | Root or own account |
-n, -x, -w, -i | Set minimum age, maximum age, warning and inactive days | Root |
--stdin | Reads the new password from standard input | Root, some distributions only |
A key subtlety is that locking with `-l` does not block every login method. It invalidates the password hash only, so a user with an authorized SSH key can still log in. To disable an account completely, administrators combine password locking with usermod --expiredate 1 or set the login shell to nologin.
Password aging fields
Password aging in Linux is controlled by numeric fields in each shadow entry, counted in days since 1 January 1970. passwd can change most of them, while the chage command offers a fuller interface. Default values for new accounts come from /etc/login.defs, which useradd reads when creating a user.
| Field | Meaning | Typical value |
|---|---|---|
| Last change | Day of the most recent password change | Set automatically |
| Minimum age | Days before the password may change again | 0 to 1 |
| Maximum age | Days before a change is required | 99999 or 90 to 365 |
| Warning period | Days of warning before expiry | 7 |
| Inactive period | Days after expiry before the account is disabled | Empty or 30 |
| Account expiry | Absolute date when the account stops working | Empty unless set |
Current guidance such as NIST SP 800-63B discourages forced periodic rotation without evidence of compromise, because it pushes users toward predictable patterns. Many organizations therefore set a long or unlimited maximum age and rely on length, breach checks and multi-factor authentication instead.
passwd compared with related account commands
passwd is one of several account management tools in the Permissions toolbox, and each has a distinct purpose. Confusing them leads to scripts that silently do the wrong thing.
| Command | Main purpose | Changes the password hash |
|---|---|---|
| passwd | Change, lock or expire one password | Yes |
| chpasswd | Set many passwords from name:password pairs | Yes |
| chage | Edit aging and expiry fields | No |
| usermod | Change shell, groups, home, lock state | Only with -p or -L |
| useradd | Create an account | No, unless -p is given |
| su and sudo | Run commands as another user | No |
For automated provisioning, chpasswd is the safer choice because it reads pairs from standard input; passing a password as a command-line argument exposes it in the process list and shell history.
Security considerations and common mistakes
Because passwd is setuid root, it is a high-value target and is kept deliberately small and audited. Administrators should not change its mode, and file integrity tools commonly alert if its hash or permissions change.
- Running
passwd -dcreates a passwordless account, which may allow local login without credentials. - Editing
/etc/shadowby hand risks syntax errors; use passwd, chage orvipw -sfor safe locked editing. - On systems joined to LDAP or Active Directory, passwd may change the remote directory password through PAM rather than the local file.
- Error messages such as BAD PASSWORD come from PAM quality rules, not from passwd itself.
In everyday language
passwd is the tool a Linux user types to choose a new password. Think of it as a locksmith who works at the front desk of a building. Tenants cannot open the key cabinet themselves, but the locksmith can, and he will only change the lock on your own door after you prove who you are.
The building manager, who is the administrator, can ask the same locksmith to lock any door, reset it or require a new key next week.
Seen in the real world
A university lab administrator receives a report that a former teaching assistant still has an account on a shared Linux compute server. The administrator runs passwd -S tassist and sees that the password is set and was last changed 200 days ago. She runs passwd -l tassist to lock the password and, because the account also has an SSH key, adds usermod --expiredate 1 tassist so that every login path is closed.
In the same week a new doctoral student joins the lab. The administrator creates the account with useradd, sets a temporary password with passwd and then runs passwd -e so that the student must choose a personal password at first login. The student logs in, PAM rejects a short dictionary word, and the second attempt with a long passphrase is accepted.