1、设置用户权限配置文件的权限
[root@localhost ~]# chown root:root /etc/passwd /etc/shadow /etc/group /etc/gshadow && chmod 0644 /etc/group && chmod 0644 /etc/passwd && chmod 0400 /etc/shadow && chmod 0400 /etc/gshadow
2、确保SSH LogLevel设置为INFO
[root@localhost ~]# vim /etc/ssh/sshd_config
LogLevel INFO # 取消注释,记录登录和注销活动
3、设置SSH空闲超时退出时间
[root@localhost ~]# vim /etc/ssh/sshd_config
#ClientAliveInterval 0 #取消注释,修改为ClientAliveInterval 900 ,将ClientAliveInterval 设置为300到900,即5-15分钟
#ClientAliveCountMax 3 #取消注释,修改为 ClientAliveCountMax 0
4、SSHD强制使用V2安全协议
[root@localhost ~]# vim /etc/ssh/sshd_config
新增 Protocol 2
5、确保SSH MaxAuthTries设置为3到6之间
[root@localhost ~]# vim /etc/ssh/sshd_config
#MaxAuthTries 6 #取消注释,修改为MaxAuthTries 4,设置最大密码尝试失败次数3-6,设置较低的Max AuthTrimes参数将降低SSH服务器被暴力攻击成功的风险
6、禁止SSH空密码用户登录
[root@localhost ~]# vim /etc/ssh/sshd_config
#PermitEmptyPasswords no #取消注释
7、访问控制配置置
[root@localhost ~]# chown root:root /etc/hosts.allow && chown root:root /etc/hosts.deny && chmod 644 /etc/hosts.deny && chmod 644 /etc/hosts.allow #访问控制配置文件的权限设置,CentOS 8 无需配置
8、确保rsyslog服务已启用
[root@localhost ~]# systemctl enable rsyslog && systemctl start rsyslog #确保rsyslog服务已启用,记录日志用于审计