chage Command in Linux



chage is a Linux command that is used by the system administrators to manage user password expiry information on the system. With chage command, you can view and modify details, such as the password expiry date, days between password changes, account expiration date, and last password change date. Apart from that, it also helps you control user access and security by adjusting these parameters.

Table of Contents

Installation of chage Command in Linux

chage is preinstalled on most Linux operating systems, in case it is unavailable, you can install it by installing the passwd package or shadow-utils package. For Debian-based distribution, you have to install passwd package from the apt package manager to use the chage command −

sudo apt install passwd

For other RED HAT based distributions like CentOS, you can use chage command by installing the shadow-utils package from the below-given command −

sudo yum install shadow-utils

Syntax for chage Command in Linux

The syntax for chage command on Linux is pretty simple that includes options followed by the username you want to manage, as given below −

chage [options] username

Different Options Available for chage Command

The following table summarizes the commonly used options for the chage command on Linux −

Option Description
-l Display aging information for an account.
-d or --lastday Set the change date of the last password. You can specify a number of days (NUM_DAYS) or a complete date (YYYY-MM-DD).
-E or --expiredate Adjust the account expiration date.
-i or -iso8601 Use YYYY-MM-DD when printing dates.
-I or --inactive Specifies the number of days before a password expires when the user receives a warning message.
-m or --mindays Changes the minimum number of days between password changes. A value of 0 allows password changes anytime.
-M or --maxdays Specifies the maximum number of days between password changes.
-R or --root Directory to chroot into
-W or --warndays Set expiration warning days to WARN_DAYS

Examples of chage Command in Linux

Let’s explore a few examples of chage command on Linux −

Note − You must run the chage command with sudo privileges since we are going to do system related tasks.

Display Aging Information

Aging information for an account refers to details related to password expiration and account management. You can display aging information for an account on your Linux system by using the chage command with the -l option and username in the last.

For example, to display the aging information for the username “ubuntu”, you can use the following command −

sudo chage -l ubuntu
Display Aging Information

Modify Last Password Change Date

If you want to set the last password change date for a user, you can use the -d or --lastday option followed by the desired date. The date can be either a number of days or a complete date in YYYY-MM-DD format).

For example, to change the last password change date for “ubuntu” to June 15, 2024, you can use the following command −

sudo chage -d 2024-06-15 ubuntu
Modify Last Password Change Date

Set Account Expiration Date

You can also specify the account expiration date by using the -E or --expiredate option with the chage command followed by the desired date. For example, to set the account expiration date for user “ubuntu” to December 31, 2024, you can use the below-given command −

sudo chage -E 2024-12-31 ubuntu
Set Account Expiration Date

Minimum Days between Password Change

You can also change the minimum number of days required between password changes using the -m or --mindays option with the chage command. For example, to enforce a minimum of 10 days between password changes for a user “ubuntu”, the following command is used −

sudo chage -m 10 ubuntu
Minimum Days between Password Change

Maximum Days between Password Change

To specify the maximum days allowed before a password change is required, you can use the -M or --maxdays option with the chage command. For example, to set a maximum of 90 days between password changes for a user “ubuntu”, use the following command −

sudo chage -M 90 ubuntu
Maximum Days between Password Change

Set Inactivity Period after Password Expiry

If you want to define the number of days of inactivity after password expiry, you can use the -I option with the chage command. For example, if you want to lock the account of “ubuntu” after 30 days of inactivity, the following command will be used −

sudo chage -I 30 ubuntu
Set Inactivity Period after Password Expiry

Set Last Password Change Date Explicitly

To explicitly set the last password change date to today, the cheg command will be used with the -d option. For example, to set the last password change date for used “ubuntu” to today, you can run the below-given command −

sudo chage -d $(date +%Y-%m-%d) ubuntu
Set Last Password Change Date Explicitly

Remove Account Expiration Date

You can also remove the account expiration date (make it indefinite) with the chage command by using the -E option with -1. For example, to remove the expiration date for “ubuntu”, run the below–given command −

sudo chage -E -1 ubuntu
Remove Account Expiration Date

Set Expiration Warning Days

If you want to specify the number of days before password expiration when the user receives a warning,, simply use the -W option. For example, to warn user “ubuntu” 10 days before password expiration, the following command will be used −

sudo chage -W 10 ubuntu
Set Expiration Warning Days

That’s how the chage command is used on Linux systems.

Conclusion

In Linux, the chage command is used for viewing and changing the user password expiry information. You can use the chage command to display aging information, modify last password change, and set account expiration date. Also, you can set min and max days between password change, inactivity period, last password change, remove account expiration and expiration warning days.

Advertisements