我可以阻止来自外部notwork的root ssh访问,但不能阻止来自本地LAN的访问
操作系统:Ubuntu 14.04
我想从本地登录ssh,因为backuppc需要它。 我想用root登录阻止外部访问。
谢谢
您可以使用/etc/ssh/sshd_config
的Match
块执行此操作。 首先,确保你有这一行:
PermitRootLogin no
这将阻止root访问。 然后,您可以将其用于本地网络:
## Permit local root login Match Address 192.168.1.*,127.0.0.1 PermitRootLogin yes
这假设您的LAN提供类似192.168.1.N
IP,如果没有,则相应地更改。 另外,我建议你在/etc/ssh/sshd_config
的末尾添加它,以确保它不与其他指令冲突。 完成后,重新启动ssh服务( sudo service ssh restart
),您将能够仅从本地计算机以root身份ssh。
使用这个简单的iptables规则,您可以阻止不是来自本地网络的主机,我的网络是192.168.122.0所以我的规则是:
iptables -A INPUT -i eth0 -p tcp --dport 22 ! -s 192.168.122.0/24 -j DROP
如果您只想阻止源中的特定用户
在/ etc / ssh / sshd_config中
AllowUsers root@192.168.122.*
经过这个问题的处理后我发现,与IP6相互作用你应该合理地需要添加:: 1作为localhost起源
# Authentication: LoginGraceTime 120 PermitRootLogin no StrictModes yes ## Permit local root login Match Address ::1,127.0.0.1 PermitRootLogin yes Match All