Quick take: Run passwd to change your own password, or sudo passwd username to set another user's. Administrators can lock an account with -l, unlock it with -u, and force a password change with -e.
Introduction
The passwd command manages account passwords. Any user can change their own with a plain passwd, while administrators use it to set or reset other users' passwords, lock and unlock accounts, and enforce password aging policies.
This guide covers changing passwords, locking accounts, forcing resets, and the expiry options that support good password hygiene.
Syntax
The basic syntax of the passwd command is:
passwd [OPTIONS] [USERNAME]Common Options and Parameters
The most useful options and parameters for the passwd command:
| Option | Description |
|---|---|
| -l | Lock the account (disable password login). |
| -u | Unlock a locked account. |
| -e | Expire the password, forcing a change at next login. |
| -d | Delete the password (passwordless — use with caution). |
| -S | Show the account's password status. |
| -n DAYS | Minimum days between password changes. |
| -x DAYS | Maximum days a password is valid. |
| -w DAYS | Warning days before expiry. |
Practical Examples
Real passwd commands you can run today:
# Change your own password
passwd
# Set another user's password (admin)
sudo passwd alice
# Lock an account
sudo passwd -l alice
# Unlock an account
sudo passwd -u alice
# Force a password change at next login
sudo passwd -e alice
# Check an account's password status
sudo passwd -S aliceTips and Best Practices
- Locking with
passwd -lonly disables password login; if the user has SSH keys, also disable those to fully block access. - Use
passwd -eafter creating an account so the user must set their own password on first login. - For detailed aging policy,
chageoffers a fuller view than passwd's expiry flags.
Final Thoughts
passwd is the front line of account security — changing passwords, locking compromised accounts, and enforcing expiry. Remember -l/-u to lock and unlock, -e to force a reset, and -S to check status. For onboarding, set a temporary password and expire it so users choose their own on first login.
FAQ: passwd Command in Linux
How do I change my password in Linux?+
Just run passwd with no arguments. You will be prompted for your current password, then the new one twice. No sudo is needed to change your own password.
How do I change another user's password?+
Use sudo: sudo passwd username lets an administrator set or reset any user's password without knowing the old one.
How do I lock a user account?+
Use sudo passwd -l username to lock it, which disables password login. Unlock it again with sudo passwd -u username. Remember to also disable SSH keys if the user has them.
How do I force a user to change their password at next login?+
Use sudo passwd -e username, which expires the current password so the user must set a new one the next time they log in.
How do I check a user's password status?+
Run sudo passwd -S username to see whether the password is set, locked, or expired, along with its aging information.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support