Linux SSH安全加固

Linux SSH 安全加固,这里使用CentOS7.5 做演示

一、配置SSH双因素登录

​ 1.确定系统时钟是正确的

2.安装相关依赖

​ yum install -y git gcc automake autoconf libtool make pam-devel

​ 3.安装google 验证器

git clone https://github.com/google/google-authenticator-libpam
cd google-authenticator-libpam
./bootstrap.sh
./configure
make && make install
ln -fs /usr/local/lib/security/pam_google_authenticator.so /lib64/security/

​ 4.配置验证器
​ 修改SSH文件 将ChallengeResponseAuthentication 修改为yes
​ 修改PAM文件 vim /etc/pam.d/sshd 在auth substack password-auth下面一行添加 auth required pam_google_authenticator.so
​ 关闭selinux 修改/etc/sysconfig/selinux 文件 将 SELINUX=enforcing 修改为disabled
​ google-authenticator
​ 重启SSH服务

二、设置密码长度以及复杂度

​ 1.设置密码长度

修改 /etc/login.defs文件
将PASS_MIN_LEN 数值修改
修改 /etc/pam.d/system_auth配置文件
在password requisite 行后边添加: minlen=数值

​ 2.设置密码复杂度

方法一:修改/etc/pam.d/system-auth
在password requisite 行后边添加:
    ucredit=-1 #至少包含1位大写字母
    lcredit=-1 #至少包含1位小写字母
    ocredit=-1 #至少包含1位特殊字符
    dcredit=-1 #至少包含1位数字
方法二:使用如下命令:
    authconfig --enablereqlower --update
    authconfig --enablerequpper --update
    authconfig --enablereqdigit --update
    authconfig --enablereqother --update

三、设置密码重试限制

1.限制tty登录

修改login文件:
# vi /etc/pam.d/login
在#%PAM-1.0下面插入一行,也就是在第二行插入如下内容:
auth required pam_tally2.so deny=5 unlock_time=1800 even_deny_root
root_unlock_time=3600
# 注意:上述配置必须在第二行,否则即使用户被锁定了,输入正确的用户名和密码也可以登录的。
# 普通用户和root用户,密码输入错误5次,都会被锁定,普通用户被锁定1800秒,root用户被锁定3600秒
# deny=5表示密码输入错误5次
# unlock_time=1800表示普通用户锁定的时间,单位为秒
# root_unlock_time=3600表示root用户锁定的时间,单位为秒
# even_deny_root表示root用户也锁定

2.限制ssh登录

# vi /etc/pam.d/sshd
在#%PAM-1.0下面插入一行,也就是在第二行插入如下内容:
auth required pam_tally2.so deny=5 unlock_time=1800 even_deny_root
root_unlock_time=1800
# 注意:上述配置必须在第二行,否则即使用户被锁定了,输入正确的用户名和密码也可以登录的。

参考链接 :
CentOS7.0系统安全加固手册 : https://www.jianshu.com/p/501346ec6b26

作者:Odinmx
链接:https://www.jianshu.com/p/a953e70ea997
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

发布了313 篇原创文章 · 获赞 57 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qq_40907977/article/details/104198790