如何在Ubuntu 20.04/CentOS 8上加强和保护SSH
时间:2020-03-21 11:43:58 来源:igfitidea点击:
在对任何Linux服务器执行任何远程登录时,SSH扮演着最重要的角色。
这就是为什么它是任何黑客入侵Linux服务器的第一个有针对性的方法。
由任何系统管理员或者Devops工程师执行的第一步是加固SSH,以使其免受外部攻击和黑客攻击。
本教程说明了如何使用SSH强化技巧来保护Linux SSH服务器。
提示1:启用防火墙以保护SSH端口。
首先,我们需要使用UFW防火墙和Firewalld防火墙集成防火墙以保护SSH端口。
提示2:启用基于SSH密钥的身份验证,而不是基于密码的身份验证。
其次,我们需要启用基于密钥的SSH身份验证以保护SSH服务器。
提示3:强化sshd配置文件。
然后编辑SSH配置文件。
# vim /etc/ssh/sshd_config
之后,找到给定的行
PermitRootLogin yes PasswordAuthentication yes AllowTcpForwarding YES ClientAliveCountMax 3 Compression DELAYED LogLevel INFO MaxAuthTries 6 MaxSessions 10 Port 22 TCPKeepAlive YES UsePrivilegeSeparation YES X11Forwarding YES AllowAgentForwarding YES
尽快将其更改为
PermitRootLogin no PasswordAuthentication no AllowTcpForwarding NO ClientAliveCountMax 2 Compression NO LogLevel VERBOSE MaxAuthTries 2 MaxSessions 2 Port 3526 TCPKeepAlive NO UsePrivilegeSeparation SANDBOX X11Forwarding NO AllowAgentForwarding NO
最后,重新启动SSH服务使更改生效。
# systemctl restart sshd
提示4:集成基于高级Diffie-Hellman密钥的算法以保护SSH。
首先集成基于Diffie-Hellman密钥的高级算法,以提高SSH服务器的安全性。
提示5:使用Fail2ban限制SSH蛮力攻击。
其次,使用Fail2ban限制SSH蛮力攻击。
在基于Ubuntu/Debian的发行版上安装Fail2ban,
# apt install fail2ban -y
在基于RHEL/CentOS的发行版上安装Fail2ban。
注意:我们需要先安装EPEL信息库,然后再继续执行给定的步骤。
# yum install fail2ban -y
在Linux发行版上启用fail2ban。
# cp -rv /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
启动fail2ban服务使更改生效。
# systemctl start fail2ban
现在我们已经在Ubuntu和CentOS上强化并保护了SSH。