一、chage命令使用方法以及常用参数
chage #修改账号和密码有效期限
语法:chage [参数] [数值] username
常用参数:
-l # 列出当前用户过期时间设置信息
-m # 密码可以更改的最小天数,为0时任何时候都能更改
-M # 密码保持有效的最大天数
-E # 设置用户的过期时间 过了这些天账号将不可用 0表示马上过期 -1表示永不过期
-d # 上一次更改的日期
二、测试并查看
1、新建测试账号 test
# useradd test
# passwd test
2、查看账号密码过期时间等信息
# chage -l test
[root@centos7 ~]# chage -l test
Last password change : Apr 27, 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
3、设置密码过期时间
# passwd -x 90 test
[root@centos7 ~]# passwd -x 90 test
Adjusting aging data for user test.
passwd: Success
[root@centos7 ~]# chage -l test
Last password change : Apr 27, 2021
Password expires : Jul 26, 2021
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
4、设置用户test密码永不过期。
# chage -M 99999 test
[root@centos7 ~]# chage -M 99999 test
[root@centos7 ~]# chage -l test
Last password change : Apr 27, 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
5、设置test用户过期时间
# chage -E 60 test
[root@centos7 ~]# chage -E 60 test
[root@centos7 ~]# chage -l test
Last password change : Apr 27, 2021
Password expires : never
Password inactive : never
Account expires : Mar 02, 1970
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
6、查看结果解释说明
[root@centos7 ~]# chage -l test
Last password change : Apr 27, 2021【最近一次修改密码的时间】
Password expires : Jul 26, 2021【密码过期时间】
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 : 15 【密码过期前开始警告的天数】