Definition:
If you need to set or update a user’s password, you use this command in the terminal.
It helps protect user accounts and their files and folders from hacking or unauthorized access.
Syntax:
passwd [options] [username]
Example 1 – Change your own password
passwd
Output:
Changing password for user shobha. (current) UNIX password: New password: Retype new password: passwd: password updated successfully
Here, the user shobha updated her own password.
Example 2 – Admin sets a password for a new user
passwd prabha
Output:
New password: Retype new password: passwd: password updated successfully
Here, the admin set a password for Prabha.
Example 3 – Lock a user account
passwd -l ravi
Output:
passwd: password expiry information changed.
Here, Ravi’s user account was locked.
Example 4 – Unlock a user account
passwd -u ravi
Output:
passwd: password expiry information changed.
Here, the admin has unlocked Ravi’s account, allowing him to log in again.
Options:
-l→ If you use this option, it locks the user’s password (disabling login).-u→ If you use this option, it unlocks the user’s password (enabling login).-d→ If you use this option, it deletes the user’s password (no password required for login).-e→ If you use this option, it forces the user to change the password at the next login.-n DAYS→ If you use this option, it specifies the minimum number of days that must pass before the user can change their password.-x DAYS→ If you use this option, it specifies the maximum number of days a user can keep the same password before being required to change it.-w DAYS→ If you use this option, it sets the warning period (before password expiry) in days.-i DAYS→ If you use this option, it sets the number of inactive days after password expiry before the account is disabled.
