Introduction to chage command in Linux
chage
command is used to view and modify the user's account and password expiry information. It modifies the date of password expiry, last password change, and account expiry. System administrators can use this command to manage the aging information of accounts.
In this article, you will find the different examples of chage
command to change the aging information of a user.
Different examples to use chage command
Only the root user or sudo
users can execute the chage
command. It takes the user name as an argument.
The syntax for chage command is:
$ sudo chage [options] user
1. Show the account aging information with chage command
-l
option shows the aging information of an account.
$ sudo chage -l user
Sample Output:
2. chage command to modify the last password change date
You can use -d
or --lastday
option to modify the last password change date. It takes a number of days(NUM_DAYS) or a complete date as an argument. If you specify the number of days, it will assign the date after NUM_DAYS since January 1st, 1970. You should provide the date in YYYY-MM-DD format.
$ sudo chage -d YYYY-MM-DD user
OR
$ sudo chage --lastday YYYY-MM-DD user
Sample Output:
3. chage command to set the account expiry date
You can set or edit the account expiry date by using -E
or --expiredate
option.
$ sudo chage -E YYYY-MM-DD user
OR
$ sudo chage --expiredate YYYY-MM-DD user
Sample Output:
4. Set the minimum number of days between password change
You can use -m
or --mindays
option to change the minimum number of days between password change. The user cannot change his/her password before the minimum days between password change. The number 0
indicates that the user can change the password anytime.
$ sudo chage -m NUM_DAYS user
OR
$ sudo chage --mindays NUM_DAYS user
Sample Output:
5. Set the maximum number of days between password change
The maximum number of days after which the password will expire. You can change it using -M
or --maxdays
option. When the maximum days and last password change date is less than the current date, the user will need to change the password to use the account. The value -1
in this field removes the password validity.
$ sudo chage -M NUM_DAYS user
OR
$ sudo chage --maxdays NUM_DAYS user
Sample Output:
As you can see, it also updated the password expiry date , after which the password will expire.
6. chage command to set the number of days of inactivity
-I
or --inactive
option sets the number of days of inactivity after the password has expired. The account will be locked after this time period of inactivity.
$ sudo chage -I NUM_DAYS user
OR
$ sudo chage --inactive NUM_DAYS user
Sample Output:
The value -1
in NUM_DAYS removes the account inactivity.
7. Set the number of days of warning before password expires
The user will be warned before his/her password expiry date. To set or modify the number of days of warning before a password expires, you can use -W
or --warndays
option.
$ sudo chage -W NUM_DAYS user
OR
$ sudo chage --warndays NUM_DAYS user
Sample Output:
8. Using chage command without any options (interactive)
You can use chage
command without any options. It asks the users to enter the value for all the fields. You can either enter a new value to change the field or leave a blank to keep the current value. The current values are displayed between [ ] brackets.
$ sudo chage user
Sample Output:
9. chage command to set password expires to never
To change the value in password expires, you have to modify the value in maximum number of days between password change. If you put the value -1
in it, it will set the password expires to never.
$ sudo chage -M -1 user
Sample Output:
10. Remove expiry date from user account with chage command
You can change the value in Account expires using -E
or --expiredate
option. If you provide the value -1
, it will remove the account expiry date.
$ sudo chage -E -1 user
Sample Output:
Conclusion
These are the most important chage
command examples in Linux. You can use this command to view and manage the user's account and password expiry date.
What's Next
15 most used usermod command examples in Linux
Further Reading