Concepts

The passwd command changes passwords for user accounts. A normal user may only change the password for their own account, while the superuser may change the password for any account. passwd also changes the account or associated password validity period.

Options & Arguments

passwd [options] [LOGIN]

  • If the LOGIN is not specified, the current login user is assumed.
  • $ passwd 修改当前用户的密码
  • $ sudo passwd root 修改 root 用户密码 | Option | Long Option | Description | | —- | —- | —- | | -l | —lock |
    - Lock the password of the named account. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a ´!´ at the beginning of the password).
    - Note that this does not disable the account. The user may still be able to login using another authentication token (e.g. an SSH key). To disable the account, administrators should use usermod --expiredate 1 (this set the account’s expire date to Jan 2, 1970).
    - Users with a locked password are not allowed to change their password.
    | | -u | —unlock | Unlock the password of the named account. This option re-enables a password by changing the password back to its previous value (to the value before using the -l option). | | -d | —delete | Delete a user’s password (make it empty). This is a quick way to disable a password for an account. It will set the named account passwordless. | |

    -n, —mindays MIN_DAYS | | Set the minimum number of days between password changes to MIN_DAYS.
    A value of zero for this field indicates that the user may change their password at any time. | | -x, —maxdays MAX_DAYS | | Set the maximum number of days a password remains valid. After MAX_DAYS, the password is required to be changed.
    Passing the number -1 as MAX_DAYS will remove checking a password’s validity. | | -w, —warndays WARN_DAYS | | Set the number of days of warning before a password change is required.
    The WARN_DAYS option is the number of days prior to the password expiring that a user will be warned that their password is about to expire. | | -k | —keep-tokens | Indicate password change should be performed only for expired authentication tokens (passwords). The user wishes to keep their non-expired tokens as before. | | -i, —inactive INACTIVE | | 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. | | -e | —expire | Immediately expire an account’s password. This in effect can force a user to change their password at the user’s next login. |