我想限制我的SSHlogin只有一个IP地址,所以我修改了以下文件
$ nano /etc/ssh/sshd_config
并添加了这条线(即我的IP),希望它会工作
ListenAddress 172.168.0.21
但没有运气连接拒绝我不想使用任何iptables的事情。 为什么它不以这种方式工作,我如何解决这个问题,以及任何解释?
我必须同意dunxd,IPTables不应该作为一个可行的方法打折扣。 然而,你很幸运,因为你可以利用tcpwrappers来实现相同的function。 虽然比表面上更复杂,但tcpwrappers基本归结为两个文件:/etc/hosts.allow和/etc/hosts.deny如果这些文件还不存在,可以安全地将它们创build为空文件: sudo touch /etc/hosts.{allow,deny}
。
现在是时候让事情变得更复杂了。 保护networking访问的“最佳”方法是将您的默认设置(仅hosts.deny)设置为ALL:ALL
,但这可能会导致意外的访问限制。 出于这个原因和这个问题的目的,在/etc/hosts.deny中inputsshd:ALL
就足够了,它将禁止所有ssh访问主机。
就sshd而言,/etc/hosts.allow中的所有条目现在将取代默认的拒绝规则: sshd: 172.168.0.21
将只允许访问主机172.168.0.21并拒绝所有其他条目。
tcpwrappers文件接受逗号分隔的条目列表,因此您可以将地址附加到上面的第一个条目。 tcpwrappers也接受部分IP地址作为子网,所以你可以允许整个172.168.0.0/24作为sshd: 172.168.0.
请参阅手册页以获取更多详细信息。 tcpwrappers实际上function非常丰富,我推荐阅读上面的简要介绍。
你可以在/ etc / ssh / sshd_config中使用AllowUsers
指令
AllowUsers [email protected]
如果您在sshd_config文件中进行了任何更改,请不要忘记重新启动sshd。
从sshd_config手册页
This keyword can be followed by a list of user name patterns, separated by spaces. If specified, login is allowed only for user names that match one of the patterns. '*' and '?' can be used as wildcards in the patterns. Only user names are valid; a numerical user ID is not recognized. By default, login is allowed for all users. If the pattern takes the form USER@HOST then USER and HOST are separately checked, restricting logins to particular users from particular hosts.
没有iptables,我会说这是不可能的。
在sshd_config中使用ListenAddress意味着你将ssh守护进程绑定到特定的(本地)ip地址。 如果您的系统上没有ip地址,sshd可能会失败。
看来sshd也使用libwrapper,所以你也可以定义如下:
在/etc/hosts.allow sshd:\ <您允许访问的IP地址>
在/etc/hosts.deny ALL:ALL
当然,我build议你阅读相关软件包的手册页。