$ useradd usera # 默认密码策略如下 $ chage -l usera Last password change : Dec 24, 2020 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 $ chage -d 2020-10-20 usera # 下次登录必须更改密码 $ chage -d 0 usera # 设置账户有效时间 $ chage -E 2020-12-31 usera $ chage -l usera Last password change : Oct 20, 2020 Password expires : never Password inactive : never Account expires : Dec 31, 2020 # 设置账户有效期为90天,从今天开始 $ chage -E $(date -d +90days +%Y-%m-%d) usera $ chage -l usera Account expires : Mar 24, 2021 # 设置两次密码更改的间隔天数,最少3天,最多60天.即3天内不能重复更改密码,60后必须更改密码 $ chage -m 3 -M 60 usera $ chage -l usera Last password change : Oct 20, 2020 Password expires : Dec 19, 2020 Password inactive : never Account expires : never Minimum number of days between password change : 3 Maximum number of days between password change : 60 # 设置密码永不过期-never chage -M 99999 admin
# 设置usera的密码策略,密码有效期为60天,提前14天提醒更改密码,密码过期7天后账户将失效 $ chage -m 0 -M 60 -W 14 -I 7 usera $ chage -l usera Last password change : Oct 20, 2020 Password expires : Dec 19, 2020 Password inactive : Dec 26, 2020 Account expires : never Minimum number of days between password change : 0 Maximum number of days between password change : 60 Number of days of warning before password expires : 14
# 账户密码未过期之前提示信息如下,截止日期为Password expires Warning: your password will expire in 3 days
# 账户密码过期之后且在密码失效之前提示需要更改密码,截止日期为Password inactive WARNING: Your password has expired. You must change your password now and login again! Changing password for user usera. Changing password for usera. (current) UNIX password: New password:
# 密码失效之后将无法登录 Your account has expired; please contact your system administrator