The chage command is identical to the passwd command used to change user account and password expiration information.
Using this command, you can list the user’s password information, enable or disable password expiration, set the account expiration date, or force the user to change their password on their next log in.
|Description||Chage (Change User Password Expiry Information)|
|Root or Sudo Privileges||Yes|
|Host System and Architecture||Ubuntu 22.10 (x64)|
|OS Compatibility||Ubuntu, Manjaro, Fedora, etc.|
Listing Password Information for the User
-l” or “
--list” flag is used to list the password information, like the last password change, password expiration, inactive status, account expiration, and the minimum and maximum number of days between password changes for the specified user.
$ sudo chage -l linuxtldr
Further, when you modify the password information of the target user, you can execute the above command to check their password status.
Maximum Number of Days to Change Password
-M” or “
--maxdays” flag will set the maximum number of days (ex: “24”) for the specified user account before the password change is acceptable.
$ sudo chage -M 24 linuxtldr
After the threshold reaches 24 days, the user must be forced to update their password.
Disable Password Expiration
If you want to avoid password expiration for the specified user account on the target days, use the “
-M” or “
--maxdays” flag and set the value to “
-1” to disable password expiration.
$ sudo chage -M -1 linuxtldr
The above command will set the “Password expires” status to “never”.
Setting the Account Expiration Date
Use the “
-E” or “
--expiredate” flag to specify the account expiration date for the specified user account in “
YYYY-MM-DD” date format.
$ sudo chage -E 2023-11-26 linuxtldr
The above command will set the “Account expires” date to “November 26, 2023” which you can verify using the “
sudo chage -l linuxtldr” command.
Forcing User to Change Password on Next Log-in
-d” or “
--lastday” flag is used to set the date of the last password change.
You can set it to 0 to force the specified user to change their password on their next log-in.
$ sudo chage -d 0 linuxtldr
Setting Days Before the Password Change is Acceptable After the Account Expired
You can use the “
-I” or “
--inactive” flag to set the number of days of inactivity allowed to the specified user account after the password is expired.
During the inactivity days, users are allowed to update their password.
After the threshold is reached on the specified day, the account will be locked.
$ sudo chage -I 18 linuxtldr
From the above command, “
linuxtldr” has 18 days to update their password after the password has expired.
Setting Password Expiration Warning Text
-W” or “
--warndays” flag is used to show a warning alarm before the number of days prior to a password change are required.
$ sudo chage -W 5 linuxtldr
The above command will show a warning message on every login five days prior to password expiration.
That was the end; the “
-i” and “
-R” flags are ignored in the article due to their lack of use in real life.
If you want them to be on the list, let us know in the comment section.