Linux chage command details

  • 2020-05-15 02:41:44
  • OfStack

Introduction to the linux chage command:

The chage command is used for password effectiveness management, which is used to modify the account and password expiration date. It can change the expiration date of your account and password. The description of the chage command is as follows:

The chage command changes the number of days between password changes and the date of the last password change. This information is used by the system to determine when a user must change his/her password

Command syntax:

chage [options] user

Command parameters:

参数

描叙

-d

指定密码最后修改日期

-E

密码到期的日期,过了这天,此账号将不可用。0表示马上过期,-1表示永不过期。

-h

显示帮助信息并退出

-I

密码过期后,锁定账号的天数

-l

列出用户以及密码的有效期

-m

密码可以更改的最小天数。为零代表任何时候都可以更改密码。

-M

密码保持有效的最大天数。

-W

密码过期前,提前收到警告信息的天数。

Use examples:

1: view the help information for the chage command

[root@DB-Server ~]#man chage
[root@DB-Server ~]# info chage
[root@DB-Server ~]# chage -h
Usage: chage [options] user

Options:

-d, --lastday LAST_DAY set 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, --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 maximim number of days before password
change to MAX_DAYS
-W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS

2: check the expiration date of the mysql user and password

[root@DB-Server ~]# chage -l mysql
Last password change : Mar 26, 2015
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : -1
Maximum number of days between password change : -1
Number of days of warning before password expires : -1
[root@DB-Server ~]#

3: set the password of mysql user to expire after 60 days, and the password can be changed after at least 7 days. The alarm message will be received 7 days before the password expires.

[root@DB-Server ~]# chage -M 60 -m 7 -W 7 mysql
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# chage -l mysql
Last password change : Mar 26, 2015
Password expires : May 25, 2015
Password inactive : never
Account expires : never
Minimum number of days between password change : 7
Maximum number of days between password change : 60
Number of days of warning before password expires : 7
[root@DB-Server ~]#
clip_image001

4: force the new user to change the password when logging in for the first time

[root@DB-Server home]# useradd test
[root@DB-Server home]# passwd test
Changing password for user test.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@DB-Server home]# chage -d 0 test
You have new mail in /var/spool/mail/root
[root@DB-Server home]# chage -l test
Last password change : password must be changed
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

Here is the linux chage command

Function: change the expiry date of account and password

Usage: chage[-l][-m mindays][-M inactive][-I expiredate][-W lastdays]username

Parameters:

-l: lists the user's and password expiry dates
-m: minimum number of days to change password
-M: maximum number of days to change password
-I: number of days after password expires
-d: specifies the date on which the password was last modified
-E: expiration date, 0 for immediate expiration, -1 for never expiration
-W: start warning days before password expires


Related articles: