Zam*_*ues 1 security ssh rhel sshd tcp-wrappers
我们在其中一台生产服务器上打开了 SSH,使其容易受到各种蛮力攻击。我通过将默认端口从 22 更改为减少了尝试次数。
我想通过仅允许从特定国家/地区域进行 ssh 登录来进一步加强安全性.in
。为此,我可以配置/etc/hosts.deny
或/etc/hosts.allow
.
对于hosts.allow
,我添加了以下条目
sshd: in
如果我使用hosts.deny
,那么我的条目是这样的
sshd: !in
配置上述任何一项后,我注意到连接到ssh
服务器需要更多时间。
在提供登录尝试之前,verbose 显示在这里挂了一段时间
ssh -vv 103.8.X.X
OpenSSH_5.9p1 Debian-5ubuntu1.4, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 103.8.X.X [103.8.X.X] port 565.
debug1: Connection established.
debug1: identity file /home/amin/.ssh/id_rsa type -1
debug1: identity file /home/amin/.ssh/id_rsa-cert type -1
debug1: identity file /home/amin/.ssh/id_dsa type -1
debug1: identity file /home/amin/.ssh/id_dsa-cert type -1
debug1: identity file /home/amin/.ssh/id_ecdsa type -1
debug1: identity file /home/amin/.ssh/id_ecdsa-cert type -1 (<-- hangs here for arnd 30 secs)
Run Code Online (Sandbox Code Playgroud)
在为 tcp 包装器设置规则后,使用 putty 需要更多时间。
将主机名放入hosts.allow
orhosts.deny
意味着服务器必须进行反向 DNS 解析才能获取 IP 地址的域名。如果您的名称解析系统缓慢或某些中间名称服务器响应缓慢,这将影响登录时间。将您的子网的 IP 地址放入文件中会更快,正如解释的那样man hosts.allow
:
The examples use host and domain names. They can be improved by includ?
ing address and/or network/netmask information, to reduce the impact of
temporary name server lookup failures.
Run Code Online (Sandbox Code Playgroud)
另一种防止暴力登录攻击的方法是安装一个名为fail2ban的程序。该程序将跟踪失败的登录尝试并在失败太多次后暂时阻止 IP 地址。这样您就不再需要根据国家/地区来阻止登录了。即使对于大型僵尸网络,每小时只允许三到四次失败的登录尝试将使暴力攻击成为不可能。
归档时间: |
|
查看次数: |
658 次 |
最近记录: |