Change password expiry in Linux

Posted on by Kim

“chage” is the command to list & change the password aging information for Linux user account. The chage command changes the number of days between password expiry and the current date. Here’s a real quick on how to show the expiration date of a particular linux user account.

Listing password aging for user:

chage command with option -l shows the password expiry details of a user. In this example, the user’s last password change was on Dec 25th 2017 and it expires in 90 days. The user will be notified within login 7 days before expiry.
 [root@centos01 ~]# chage -l demouser
 Last password change : Dec 25, 2017
 Password expires : never
 Password inactive : never
 Account expires : never
 Minimum number of days between password change : 0
 Maximum number of days between password change : 90
 Number of days of warning before password expires : 7
 [root@centos01 ~]#

Change the number of days to expire:

Use -M option and provide the number of days for expiry.
 [root@centos01 ~]# chage -M 120 demouser
 [root@centos01 ~]# chage -l demouser
 Last password change : Jan 25, 2018
 Password expires : May 25, 2018
 Password inactive : never
 Account expires : never
 Minimum number of days between password change : 0
 Maximum number of days between password change : 120
 Number of days of warning before password expires : 7
 [root@centos01 ~]#

Change the password to never expire:

You can use chage to make the password never expire with the below options. This sets password and the account to never expire.
 [root@centos01 ~]# chage -m 0 -M 99999 -I -1 -E -1 demouser
 [root@centos01 ~]# chage -l demouser
 Last password change : Jan 25, 2018
 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
 [root@centos01 ~]#

Change account expiry to specific date:

You can set the account to expire on specific day or +N number of days from the current date. Here are the examples using chage -E option.
[root@dev01 ~]# chage -E 2019-05-12 demouser
or
[root@dev01 ~]# chage -E $(date -d +180days +%Y-%m-%d) demouser
[root@dev01 ~]# chage -l demouser
Last password change : never
Password expires : never
Password inactive : never
Account expires : May 12, 2019
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
[root@dev01 ~]#

0 Responses to "Change password expiry in Linux":