我想只允许从 3 个 IP 地址进行 SSH 登录:111.111.111.111 和 222.222.222.222 和 333.333.333.333。我知道,我必须编辑 /etc/hosts.allow 和 /etc/hosts.deny 文件。
我的问题是关于这些文件的内容。我见过不同的变种:
# /etc/hosts.allow
变体 1:
sshd: 111.111.111
sshd: 222.222.222
sshd: 333.333.333
Run Code Online (Sandbox Code Playgroud)
变体 2:
sshd: 111.111.111, 222.222.222, 333.333.333
Run Code Online (Sandbox Code Playgroud)
变体 3:(不带逗号):
sshd: 111.111.111 222.222.222 333.333.333
Run Code Online (Sandbox Code Playgroud)
变体 4(使用 sshdfwd-X11):
sshd,sshdfwd-X11: 111.111.111 222.222.222 333.333.333
Run Code Online (Sandbox Code Playgroud)
/etc/hosts.deny
变体 1:
sshd: ALL
Run Code Online (Sandbox Code Playgroud)
变体2:
sshd,sshdfwd-X11:ALL
Run Code Online (Sandbox Code Playgroud)
哪个是正确的?我害怕把我锁在外面。谢谢。
我会在sshd_config使用AllowUsers.
AllowUsers = *@111.111.111.111, *@222.222.222.222, *@333.333.333.333
Run Code Online (Sandbox Code Playgroud)
对我来说,这会将所有配置保存在与您控制的应用程序关联的位置。总是有不止一种方法可以用 UNIX 给猫剥皮,但是如果该工具提供了特定的控制机制,我倾向于比其他任何东西都更喜欢它(它通常更便携)。
在更改与远程访问相关的任何内容时,
我发现只要你已经有几个远程会话,你就会没事的。更改/etc/ssh/sshd_config和回收 SSH 不会断开任何现有会话。
虽然我很感激这并没有回答你的具体问题。我相信杰夫的回答确实如此(因为如果您使用/etc/hosts.deny或,所有这些变体都是有效的/etc/hosts.allow)。