Changing password expiry information

How to change password expiry information

The chage command is used to modify a Linux users password expiry information. The chage command changes the number of days between password changes and the date of the last password change. "chage" may only be used by the "root" user. However, the "chage -l" option that lists your current expiry status can be used by anyone with a valid account.

Chage command available options

Below are the options that can be used by the "chage" command.


Usage: chage [options] LOGIN

Options:
  -d, --lastday LAST_DAY        set date of last password change to LAST_DAY
  -E, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -h, --help                    display this help message and exit
  -i, --iso8601                 use YYYY-MM-DD when printing dates
  -I, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -l, --list                    show account aging information
  -m, --mindays MIN_DAYS        set minimum number of days before password
                                change to MIN_DAYS
  -M, --maxdays MAX_DAYS        set maximum number of days before password
                                change to MAX_DAYS
  -R, --root CHROOT_DIR         directory to chroot into
  -W, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS


Displaying Password Expiry Information for a user

chage -l user


root@mint01a:~# chage -l testuser
Last password change					: Apr 20, 2021
Password expires					: never
Password inactive					: never
Account expires						: never
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7

The above "chage" example displays password expiry information for the specified user.

Changing Password expiry information interactively

chage user


root@mint01a:~# chage testuser
Changing the aging information for testuser
Enter the new value, or press ENTER for the default

	Minimum Password Age [0]: 
	Maximum Password Age [99999]: 90
	Last Password Change (YYYY-MM-DD) [2021-04-20]: 
	Password Expiration Warning [7]: 10
	Password Inactive [-1]: 
	Account Expiration Date (YYYY-MM-DD) [-1]: 2022-04-20

root@mint01a:~# chage -l testuser
Last password change					: Apr 20, 2021
Password expires					: Jul 19, 2021
Password inactive					: never
Account expires						: Apr 20, 2022
Minimum number of days between password change		: 0
Maximum number of days between password change		: 90
Number of days of warning before password expires	: 10

When you run the "chage" command interactively, you are prompted to enter new values. Simply enter the details you wish to change.

Force a user to change their password at next login

chage -d 0


root@mint01a:~# chage -d 0 testuser
 
root@mint01a:~# chage -l testuser
Last password change					: password must be changed
Password expires					: password must be changed
Password inactive					: password must be changed
Account expires						: Apr 20, 2022
Minimum number of days between password change		: 0
Maximum number of days between password change		: 90
Number of days of warning before password expires	: 10

The command "chage -d 0 userid" is used to force a user to change their password the next time they login.