Linux – passwd Command

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.



Tutorials dojo strip

Initial Example

To change the current user’s password, simply type:

passwd




PASSWD Parameters

ParameterDescription
-a, --allDisplay password status information for all users, used only with the -S option.
-d, --deleteRemove a user’s password, making the account passwordless.
-e, --expireImmediately expire the user’s password, requiring a password change at the next login.
-h, --helpDisplay help message and exit.
-i, --inactive INACTIVEDisable an account after the password has been expired for a specified number of days.
-k, --keep-tokensChange only expired authentication tokens, keeping non-expired tokens unchanged.
-l, --lockLock a user’s password, preventing login with the password but not disabling the account entirely.
-n, --mindays MIN_DAYSSet the minimum number of days required between password changes.
-q, --quietOperate in quiet mode, suppressing output.
-r, --repository REPOSITORYChange the password in the specified repository.
-R, --root CHROOT_DIRApply changes in the specified chroot directory.
-P, --prefix PREFIX_DIRApply changes to configuration files under the specified root filesystem directory.
-S, --statusDisplay account status information, including password status and expiration details.
-u, --unlockUnlock a previously locked password, restoring the previous password value.
-w, --warndays WARN_DAYSSet the number of days of warning before a password change is required.
-x, --maxdays MAX_DAYSSet the maximum number of days a password remains valid before it must be changed.
-s, --stdinRead 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




Linux Playground

Scroll to Top