The passwd command in Unix-like operating systems is used for changing user passwords. It provides various options for password management. This cheat sheet covers essential passwd commands for users and system administrators.
Introduction:
The passwd command is a crucial tool for managing user passwords on Unix-based systems. It allows users to change their own passwords and administrators to modify other user accounts.
Basic Commands:
Command
Description
passwd
Change the password for the current user.
passwd [username]
Change the password for a specific user (requires sudo).
passwd -l [username]
Lock the password of a user account.
passwd -u [username]
Unlock the password of a previously locked account.
passwd -d [username]
Delete the password of a user account (set to empty).
Password Policies:
Command
Description
passwd -e [username]
Expire the password of a user, forcing them to change it on next login.
passwd -n [min_days] [username]
Set the minimum number of days between password changes.
passwd -x [max_days] [username]
Set the maximum number of days a password is valid.
Administrative Commands:
Command
Description
passwd -S [username]
Display the password status (age, expire, etc.) for a user.
passwd -l -e [date] [username]
Lock and expire a user account on a specific date.
passwd -S -a
Display password status for all user accounts.
`passwd -S -a
awk ‘$2 ~ /LK/ {print $1}’`
Security Tips:
Command
Description
passwd --stdin [username]
Set the password from standard input (useful for scripts).
passwd --warndays [days] [username]
Set the number of days before a password expires to give a warning.
passwd --mindays [days] [username]
Set the minimum number of days between password changes.
passwd --maxdays [days] [username]
Set the maximum number of days a password is valid.
Miscellaneous:
Command
Description
passwd --status
Display the password status for the current user.
passwd --help
Display help and usage information for passwd.
Conclusion
The passwd command is a fundamental tool for managing user passwords on Unix-like systems. This cheat sheet provides essential commands for users and administrators to change passwords, set password policies, and perform administrative tasks. Whether you are an individual user or a system administrator, these commands will help you effectively manage user passwords on your Unix-based system.