如果您只需要从一个 IP 地点举行远程访问(好比从工作地点到您的家庭服务器),那么思量在您的路由器中添加防火墙规则来过滤防火墙上的毗连,将访问限制为仅该特定的 IP 地点。
在防火墙服务中使用 rich-rules 来允许 SSH 只在特定的端口上。源地点可以是单个地点,也可以是带位掩码的基址:
# use 'ssh' or 'ssh-custom' depending on which are enabled and available$ firewall-cmd --permanent --remove-service="ssh" $ firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="72.232.194.162" service name="ssh-custom" accept'$ firewall-cmd --reload
复制代码
SSH also natively supports TCP wrappers and access to the ssh service may be similarly controlled using hosts.allow and hosts.deny.
如果您不能限制源 IP 地点,而且必须全局打开 SSH 端口,那么可以限制其尝试毗连的次数:
# use 'ssh' or 'ssh-custom' depending on which are enabled and available$ firewall-cmd --permanent --remove-service="ssh"$ firewall-cmd --permanent --add-rich-rule='rule service name="ssh-custom" accept limit value="4/m" log'$ firewall-cmd --reload
Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'.Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:pT1KVqS9SdC9MUkCcR1JfRGDS8NhO8dj2G3uR3mbhU0 root@localhost.localdomainThe key's randomart image is:+---[RSA 2048]----+| +++==Bo+o|| *..O=* +|| . = .BoBE|| * o..+*o|| S = ..*|| o . . o=|| . oo|| .|| |+----[SHA256]-----+