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

 

MYSQL  相关的安全策略

 


install plugin validate_password soname 'validate_password.so';


配置文件增加
plugin-load-add=validate_password.so
validate-password=FORCE_PLUS_PERMANENT

show variables like '%validate%'
--可以使用以下命令进行修改
--密码验证策略低要求(0或LOW代表低级)
set global validate_password_policy=MEDIUM;

--密码至少要包含的小写字母个数和大写字母个数
set global validate_password_mixed_case_count=1;

--密码至少要包含的数字个数。
set global validate_password_number_count=1;

--密码至少要包含的特殊字符数
set global validate_password_special_char_count=1;

-- 密码长度
set global validate_password_length=8;


--修改密码
alter user 'root'@'localhost' identified by '满足策略的密码';

--按mysql_native_password加密方式修改密码
alter user 'root'@'localhost' identified with mysql_native_password by '满足策略的密码';


# 60天内不能修改成过去使用过的前6次密码
password_reuse_interval=60
password_history=6

set global password_reuse_interval=60;
set global password_history=6;


# 需要安装connection_control插件
# install plugin connection_control soname 'connection_control';
# install plugin connection_control_failed_login_attempts soname 'connection_control';

# 查看登录失败锁定策略
show variables like '%connection_control%';
# 连续3次登录失败
connection_control_failed_connections_threshold=3
# 锁账号30分钟
connection_control_min_connection_delay=1800000

 

posted @   屌丝的IT  阅读(4157)  评论(0)    收藏  举报
点击右上角即可分享
微信分享提示