passwd (Change User Password)
The passwd command is used to change a user's password. While regular users can only change their own passwords, the superuser (root) can change the password for any account on the system.
1. Basic Usage
passwd [username]
- Running
passwdalone updates the password for the currently logged-in user. - To change another user's password, you must use sudo or be logged in as root.
2. Key Options
| Option | Name | Description |
|---|---|---|
-l |
lock | Locks the password of the named account, preventing login. |
-u |
unlock | Unlocks a previously locked account password. |
-d |
delete | Deletes a user's password (makes the account passwordless). |
-S |
status | Displays the status of the password (date changed, expiry info). |
3. Practical Examples
① Changing your own password
passwd
# Enter current password, then enter the new password twice.
② (Admin) Resetting another user's password
sudo passwd username
③ Locking a user account for security
sudo passwd -l username
4. [Tip] Password Aging
Administrators often use the chage command alongside passwd to force users to change their passwords every 90 days or to set account expiration dates.