passwd Linux Command
Changes the password for a user account.
What does passwd do?
Changes the password for a user account.
Syntax
passwd [username]Practical example
sudo passwd kaliQuestions about passwd
How do I change my own password?
Run `passwd` without any arguments. You will be prompted for your current password and then asked to enter a new one twice.
How do I change another user's password?
Use `sudo passwd username` to change another user's password. You need root privileges to do this.
How do I set a password without prompting?
Use `echo 'username:password' | sudo chpasswd` to set a password non-interactively. This is useful for scripts.
How do I lock a user's password?
Use `sudo passwd -l username` to lock the account by disabling the password. The user can still log in with SSH keys.
How do I unlock a user's password?
Use `sudo passwd -u username` to unlock a previously locked account.
How do I force a user to change password on next login?
Use `sudo passwd -e username` to expire the password. The user will be forced to set a new password at next login.
How do I check password aging info?
Use `sudo chage -l username` to see password expiration dates, last change date, and other aging information.
How do I set password expiry to 90 days?
Use `sudo chage -M 90 username` to set the maximum password age to 90 days. The user must change their password within this period.
Related User Management
sudoExecutes a command with superuser (root) privileges.
useraddCreates a new user account on the system.
suSwitches to another user account or the root user.
usermodModifies an existing user account (groups, shell, home directory, etc.).
idPrints user and group IDs (UID, GID) for the specified or current user.
userdelDeletes a user account. Use -r to also remove the home directory.