The passwd
command is used to change a user’s password in Linux. It allows both administrators and users to update passwords, enhancing security and managing access to the system.
Initial Example
To change the current user’s password, simply type:
passwd
PASSWD Parameters
Parameter | Description |
---|---|
-a, --all | Display password status information for all users, used only with the -S option. |
-d, --delete | Remove a user’s password, making the account passwordless. |
-e, --expire | Immediately expire the user’s password, requiring a password change at the next login. |
-h, --help | Display help message and exit. |
-i, --inactive INACTIVE | Disable an account after the password has been expired for a specified number of days. |
-k, --keep-tokens | Change only expired authentication tokens, keeping non-expired tokens unchanged. |
-l, --lock | Lock a user’s password, preventing login with the password but not disabling the account entirely. |
-n, --mindays MIN_DAYS | Set the minimum number of days required between password changes. |
-q, --quiet | Operate in quiet mode, suppressing output. |
-r, --repository REPOSITORY | Change the password in the specified repository. |
-R, --root CHROOT_DIR | Apply changes in the specified chroot directory. |
-P, --prefix PREFIX_DIR | Apply changes to configuration files under the specified root filesystem directory. |
-S, --status | Display account status information, including password status and expiration details. |
-u, --unlock | Unlock a previously locked password, restoring the previous password value. |
-w, --warndays WARN_DAYS | Set the number of days of warning before a password change is required. |
-x, --maxdays MAX_DAYS | Set the maximum number of days a password remains valid before it must be changed. |
-s, --stdin | Read the new password from standard input, useful for scripting. |
Examples
1. Changing Your Own Password
To change your own password, you just need to enter the passwd
command, and you will be prompted to enter your current password followed by the new password:
passwd
2. Changing Another User’s Password
To change another user’s password, a superuser or administrator can specify the username:
passwd username
3. Setting Password Expiry
To set an expiry date for a user’s password, use the -e
option followed by the username:
passwd -e username
4. Locking and Unlocking a User’s Password
To lock a user’s password, preventing them from logging in:
passwd -l username
To unlock the password:
passwd -u username
5. Displaying Password Status
To display information about a user’s password status, such as the last password change date and expiry:
passwd -S username