form1.cn
Make a little progress every day

centos7 设置复杂用户密码策略

17th of December 2019 Linux Command 2614


密码有效期控制

在文件/etc/login.defs中进行设置,如下参数

PASS_MAX_DAYS   180  #密码最长过期天数
PASS_MIN_DAYS   30  #密码最小过期天数
PASS_MIN_LEN    12  #密码最小长度
PASS_WARN_AGE   20   #密码过期警告天数


设置最小密码长度:(不少于8个字符)

authconfig --passminlen=8 --update


测试查看是否更新成功:

grep "^minlen" /etc/security/pwquality.conf


设置同一类的允许连续字符的最大数目:

authconfig --passmaxclassrepeat=4 --update


测试查看是否更新成功:

grep "^maxclassrepeat" /etc/security/pwquality.conf


新密码中至少需要一个小写字符:

authconfig --enablereqlower --update


测试查看是否更新成功:

grep "^lcredit" /etc/security/pwquality.conf


新密码中至少需要一个大写字符:

authconfig --enablerequpper --update


测试查看是否更新成功:

grep "^ucredit" /etc/security/pwquality.conf


新密码中至少需要一个数字:

authconfig --enablereqdigit --update


测试查看是否更新成功:

grep "^dcredit" /etc/security/pwquality.conf


新密码包括至少一个特殊字符:

authconfig --enablereqother --update


测试查看是否更新成功:

grep "^ocredit" /etc/security/pwquality.conf


为新密码设置hash/crypt算法(默认为sha512):


查看当前算法:authconfig --test | grep hashing


若不是建议更新:authconfig --passalgo=sha512 --update