我在hosts.deny有这个内容(最后有一个新行):
# # hosts.deny This file describes the names of the hosts which are # *not* allowed to use the local INET services, as decided # by the '/usr/sbin/tcpd' server. # # The portmap line is redundant, but it is left to remind you that # the new secure portmap uses hosts.deny and hosts.allow. In particular # you should know that NFS uses portmap! sshd : ALL
而这在hosts.allow :
# # hosts.allow This file describes the names of the hosts which are # allowed to use the local INET services, as decided # by the '/usr/sbin/tcpd' server. # sshd: our.ip.add.ress: allow
然后,我们执行这段代码重新启动SSH:
/etc/init.d/sshd restart
再次,这是最后一条新的路线。 但是,我们仍然可以从另一台服务器访问SSH服务并尝试login。 我们做错了什么?
你的/etc/hosts.deny,我认为你有一个语法错误。 “sshd”和冒号之间不应该有空格。 所以,它应该是:
sshd: ALL
在“允许”方面,我有这样的行:
sshd: 192.168.1.1
IP地址后面没有结尾的文字。
你不需要在hosts.allow : allow 。 它应该看起来像这样:
sshd: 192.168.2.200
如果您有控制台访问权限,您可以尝试阻止使用tcpwrapper的所有内容,以防服务名称出现问题:
hosts.deny :
ALL: ALL
hosts.allow :
ALL: 192.168.2.200
是否值得检查,看看对tcp-wrappers的支持是否真的被编译到你正在使用的sshd中?
它需要用–with-libwrap或–with-tcp-wrappers选项编译,根据o'reilly蜗牛书。
(我不确定是否大多数发行版默认启用此function,或者默认的编译时间选项是用于打开ssh)。
我刚刚检查我的做法是:
ldd /usr/sbin/sshd | egrep 'wrap'
其中指出
libwrap.so.0 => /lib64/libwrap.so.0 (0x00002ba50fa9c000)
(h / t到这个堆栈交换问题 )