Passwd is a basic Linux command to change the user password on Linux. A root user can change the password for any account. A normal user may only change the password for their own account. We have summarized all the options for passwd command below.
Lock an account with passwd command
Passwd -l username is used to lock the password of a specified account, and it is available to root only. The result is that the user cannot use the password to log in to the system but can use other means such as SSH public key authentication.
Disable an account with passwd command
Passwd -i no of days username: This option is used to disable an account after the password has been expired for a number of days. After a user account has had an expired password for INACTIVE days, the user may no longer sign on to the account.
Expire an account with passwd command
Passwd -e username: expire a password for an account. The user will be forced to change the password during the next login attempt.
Display the password status of user account
We can use passwd -S username to list the status of user account password settings.
Common options for passwd command
passwd -u username: unlock the password
passwd -d username: delete a password for an account
passwd -n <no of days> username: sets the number of days before a password can be changed.
passwd -x <no of days> username: Set the maximum number of days a password remains valid. After MAX_DAYS, the password is required to be changed.
passwd -w <no of days> username: This will set the number of days in advance the user will begin receiving warnings that the password will expire.
echo "howtouselinux"|passwd --stdin howtouselinux: change the password of howtouselinux user to howtouselinux in the script.