CentOS 设置密码策略


密码策略

密码有效期控制
在文件/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

直接编辑 /etc/security/pwquality.conf 这个文件 添加上述参数也是可以的

如果想让上述密码策略同样适用于root用户,那么就需要编辑文件
# vim /etc/pam.d/system-auth 文件,找到 password requisite pam_pwquality.so 这一行,添加如下语句
#password requisite pam_pwquality.so try_first_pass local_users_only retry=3 enforce_for_root

password requisite pam_pwquality.so try_first_pass local_users_only retry=3 enforce_for_root minlen=8 ucredit=-1 lcredit=-1 ocredit=-1

 

登录失败的用户锁定策略配置

#vi /etc/pam.d/sshd

auth required pam_tally2.so onerr=fail deny=3 unlock_time=300 even_deny_root root_unlock_time=300

 

 

设置SSH登录超时时间

1. /etc/ssh/sshd_config文件中的ClientAliveInterval参数。

2. /etc/profile文件中有无TMOUT环境变量设置。 例如:export TMOUT=180

3. 自己账户的.profile文件中,有无TMOUT环境变量。例如:export TMOUT=180

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM