Run passwd to change your own password, or sudo passwd username to set another user's password as root. The command asks for the current password (for your own account), then the new one twice, and writes the new hash to /etc/shadow. This is the standard passwd command linux workflow, and it also lets root lock, unlock and expire accounts.
Password changes are small but security-sensitive, so this guide also covers the options you should know and the policy checks that can reject a weak password.
Any user may change their own password by running passwd with no arguments:
Nothing is echoed while you type, which is normal. The command first checks the current password, so someone who finds your terminal unlocked cannot silently change it. If the new password is too short, too simple or the two entries differ, passwd refuses and asks again.
Root can set any password without knowing the old one:
Pass the user name explicitly, because sudo passwd with no name changes the root password. On a system where root login is disabled, that is still a risky mistake to make.
Do not set passwords in scripts with echo "bob:secret" | chpasswd unless you must automate it, because the plain text may land in shell history or process lists. If you have to, read it from a protected file or standard input:
Root administrators use these options to control account state.
| Option | Effect |
|---|---|
-l, --lock | Lock the password by putting ! before the hash |
-u, --unlock | Remove that lock |
-d, --delete | Remove the password so login needs none (avoid) |
-e, --expire | Force the user to choose a new password at next login |
-S, --status | Show the password status |
-n DAYS | Minimum days between changes |
-x DAYS | Maximum days a password stays valid |
-w DAYS | Days of warning before expiry |
-i DAYS | Days after expiry before the account is disabled |
Check an account's status:
The fields are the user, the state (P usable password, L locked, NP no password), the date of the last change, the minimum age, the maximum age, the warning period and the inactivity period.
When you create an account for someone else, set a temporary password and expire it, so the person chooses their own:
At the next login the user is asked for a new password before getting a shell.
To require a new password every 90 days with a 7-day warning:
The chage command offers the same controls with date-based options, and sudo chage -l bob prints them in readable form. Modern guidance, including NIST recommendations, favours long passphrases and changing passwords only after a suspected compromise rather than on a fixed schedule, so use forced expiry where your own policy requires it.
Locking is safer than deleting when someone leaves temporarily:
A locked password blocks password login, but it does not block SSH key login or running existing processes. To stop all logins, also expire the account with sudo usermod -e 1 bob or set a nologin shell.
On most distributions passwd runs through PAM (Pluggable Authentication Modules), which applies quality rules from pam_pwquality or pam_cracklib. Typical rejections are:
Root is warned about these rules but can often override them, while normal users cannot. The rules live in /etc/security/pwquality.conf and the PAM files under /etc/pam.d/, for example common-password on Debian and Ubuntu.
sshd_config.The terminal deliberately hides the input so nobody sees it, not even as asterisks. Type the password and press Enter.
Run sudo passwd username as root or as a user with sudo rights. For a forgotten root password you must boot into recovery mode or from a live system.
passwd -l do?It locks the password by prefixing the hash in /etc/shadow with !, so password logins fail. Existing SSH keys can still work.
No. Only root, or a user allowed through sudo, can change another account's password.
Use passwd to change your own password and sudo passwd name to set someone else's. Add -e to force a change at next login, -l and -u to lock and unlock, and -S to check status. Expect PAM quality rules to reject weak passwords, and prefer long passphrases and SSH keys for stronger security.