一、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 【密碼過期前開始警告的天數】
2021-04-27
作者 -小-白-