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
useraddneeds 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 —passwdis how those markers get set and cleared. - It’s the recovery path — when an account’s password is forgotten or expired,
sudo passwdis the fix.
Passwords are the oldest and simplest form of authentication, and
passwdis where they live. Knowing it means you can always restore access — to your own account, or (withsudo) 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 passwdskips 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
-lprefixes the stored hash with!, so no password can match — password login stops working.-Sshows 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.
chageis the reporting tool;passwdandpasswd -xare 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/passwdis world-readable and holds account metadata only — thexis a pointer./etc/shadowholds the actual hash and is readable only by root.passwdwrites 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); thexin passwd just says “hashed elsewhere”. - Forgetting
sudowhen changing someone else’s password.passwd bobas a normal user fails — it only changes your password unless you’re root. - Typo-ing a new password with no way back.
passwdasks 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 -lblocks 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
passwdchanges SSH keys. It doesn’t — key-based login is separate; see the SSH Commands page.
Related Pages
| Page | Why it’s related |
|---|---|
| useradd | Creates the accounts whose passwords you then set |
| /etc/passwd | The account file passwd’s name points at (historically) |
| su | Switching to an account needs the password you just set |
| sudo | The elevation that lets you change other users’ passwords |
| id | Verifying which account you’re changing passwords for |
| SSH Commands | Key-based login, an alternative to passwords |
passwd Cheatsheet
| Command | Meaning |
|---|---|
passwd | Change your own password |
sudo passwd username | Change another user’s password |
sudo passwd -l username | Lock an account (block password login) |
sudo passwd -u username | Unlock a locked account |
sudo passwd -S username | Show password status (P/L/NP) |
sudo passwd -x 90 user | Set maximum password age to 90 days |
sudo chage -l username | Full password expiry report |
passwd -k | (Kerberos only) renew token — rare on Linux |