passwd · Linux command

Also known as: passwd command

On this page 7

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.

FileContentsTypical modeReadable by
/etc/passwdAccount names, UIDs, shells0644All users
/etc/shadowPassword hashes and aging fields0640 or 0000Root and the shadow group
/usr/bin/passwdThe program itself4755All users, runs as root
/etc/pam.d/passwdPAM stack for password changes0644All users
Files touched by passwd

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.

OptionEffectWho may use it
-lLocks the password by prefixing the stored hashRoot
-uUnlocks a previously locked passwordRoot
-dDeletes the password, leaving the account passwordlessRoot
-eExpires the password, forcing a change at next loginRoot
-SShows status: locked, set or no password, plus agingRoot or own account
-n, -x, -w, -iSet minimum age, maximum age, warning and inactive daysRoot
--stdinReads the new password from standard inputRoot, some distributions only
Common passwd options

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.

FieldMeaningTypical value
Last changeDay of the most recent password changeSet automatically
Minimum ageDays before the password may change again0 to 1
Maximum ageDays before a change is required99999 or 90 to 365
Warning periodDays of warning before expiry7
Inactive periodDays after expiry before the account is disabledEmpty or 30
Account expiryAbsolute date when the account stops workingEmpty unless set
Shadow aging fields

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 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.

CommandMain purposeChanges the password hash
passwdChange, lock or expire one passwordYes
chpasswdSet many passwords from name:password pairsYes
chageEdit aging and expiry fieldsNo
usermodChange shell, groups, home, lock stateOnly with -p or -L
useraddCreate an accountNo, unless -p is given
su and sudoRun commands as another userNo
passwd and neighboring commands

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 -d creates a passwordless account, which may allow local login without credentials.
  • Editing /etc/shadow by hand risks syntax errors; use passwd, chage or vipw -s for 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.