说明

  chage命令用于查看或修改用户密码的有效期。

格式

  chage [option] [username]

常用参数
  • -d:设置上一次密码更改的日期
  • -E:账号过期的日期,格式YYYY-MM-DD
  • -I:设置密码过期多少天后禁用该账号
  • -l:显示账号有效期的信息
  • -m:密码可以更改的最小天数,默认为0,表示任何时间都可以更改密码
  • -M:密码保持有效的最大天数
  • -W:密码到期天,提前收到报警信息的天数
示例
1、-显示用户有效期信息
[root@localhost ~]# chage -l skip
Last password change                    : May 12, 2018
Password expires                    : Jul 11, 2018
Password inactive                    : Aug 10, 2018
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    : 10

2、要求skip用户在30天之内不能修改密码,60天后必须修改密码,过期前5天通知用户,过期5天后禁用用户登录
[root@localhost ~]# chage -m 30 -M 60 -W 5 -I 10 skip
[root@localhost ~]# chage -l skip
Last password change                    : May 12, 2018
Password expires                    : Jul 11, 2018
Password inactive                    : Jul 21, 2018
Account expires                        : never
Minimum number of days between password change        : 30
Maximum number of days between password change        : 60
Number of days of warning before password expires    : 5

3、-E参数的使用
[root@localhost ~]# chage -E "2018-12-31" skip
[root@localhost ~]# chage -l skip
Last password change                    : May 12, 2018
Password expires                    : Jul 11, 2018
Password inactive                    : Jul 21, 2018
Account expires                        : Dec 31, 2018
Minimum number of days between password change        : 30
Maximum number of days between password change        : 60
Number of days of warning before password expires    : 5