The chage
command is used to change the expiration date of an account or password on a Linux system. This command is useful for system administrators who want to enforce password policies and ensure that user accounts are secure.
Overview
The chage
command is used to modify the password expiration time for a user account. The command can be used to set the maximum number of days between password changes, the minimum number of days between password changes, and the number of days of warning before a password expires.
The basic syntax of the chage
command is as follows:
chage [options] [username]
Here, username
is the name of the user whose password expiration date you want to change. If you do not specify a username, the chage
command will modify the password expiration settings for the current user.
The chage
command can be used with various options to modify the password expiration settings. Some of the most commonly used options are:
-m, --mindays DAYS
: Specifies the minimum number of days between password changes.-M, --maxdays DAYS
: Specifies the maximum number of days between password changes.-W, --warndays DAYS
: Specifies the number of days of warning before a password expires.-E, --expiredate YYYY-MM-DD
: Specifies the date on which the user’s account will expire.
Options
The following table lists the available options for the chage
command:
Option | Description |
---|---|
-d, --lastday DAYS |
Set the number of days since January 1st, 1970 when the password was last changed. |
-E, --expiredate YYYY-MM-DD |
Set the date on which the user’s account will expire. |
-h, --help |
Display help information. |
-I, --inactive DAYS |
Set the number of days of inactivity after a password has expired before the account is locked. |
-l, --list |
Display the current password aging information for the specified user. |
-m, --mindays DAYS |
Set the minimum number of days between password changes. |
-M, --maxdays DAYS |
Set the maximum number of days between password changes. |
-R, --root CHROOT_DIR |
Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. |
-U, --unlock |
Unlock the specified user’s password. |
-W, --warndays DAYS |
Set the number of days of warning before a password expires. |
Troubleshooting tips
If you encounter issues with the chage
command, here are some troubleshooting tips:
- If you receive an error message that says “You must provide a username or UID”, make sure that you have specified a valid username.
- If you receive an error message that says “Cannot lock /etc/passwd; try again later”, it means that another process is already modifying the
/etc/passwd
file. Wait for the other process to finish before running thechage
command again. - If you receive an error message that says “Cannot determine the user name”, make sure that you have specified a valid username.
Notes
- The
chage
command is only available to users with root or sudo privileges. - The password expiration settings set by the
chage
command only apply to local user accounts. They do not affect accounts that are authenticated through a network service such as LDAP or NIS. - The
chage
command modifies the/etc/shadow
file, which contains encrypted password information. Do not modify this file manually unless you know what you are doing.