Skip to Content

4 Useful Examples of Linux Passwd Command

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 in Linux

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 in Linux

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 in Linux

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 in Linux

We can use passwd -S username to list the status of user account password settings.

Common options for passwd command in Linux

  • passwd -u username: unlock the password
  • passwd -d username: delete a password for an account
  • passwd -n username: sets the number of days before a password can be changed.
  • passwd -x username: Set the maximum number of days a password remains valid. After MAX_DAYS, the password is required to be changed.
  • passwd -w 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.

Related Post:

Basic Linux Commands: Linux User Management

Linux Userdel: Delete a User and related files