我想只允许某些主机通过SSH连接到我的服务器,并通过一个友好的错误消息拒绝其余的。 系统的授权用户通常是非技术性的,通过Filezilla访问这个系统。
我以为我可以做到这一点与TCP包装,但是当我input下面到我的hosts.deny
,客户端只是得到错误消息“ssh_exchange_identification:由远程主机closures连接”
sshd : ALL \ : twist /bin/echo "Sorry, but your host is not allowed to connect to this server." \ : deny
我遇到了一个脚本, SSH扭曲 ,似乎解决了这个问题,但我只是在客户端看到相同的错误。
对于它的价值,我正在使用OpenSSH 5.3p1在RHEL 6.1上进行testing。
SSH Twist看起来有点像黑客,我不敢打赌,它与所有的sshd
版本一起工作 – 它假设它在会话build立期间可以发送什么,这不一定是真实的。
这有点难看,但你可以在sshd_config
做这样的事情:
Match Host allowedhost1 Match Host allowedhost2 # one for each host (or hostname pattern or address range) permitted # no commands in them, just the match entries # this just makes sure they don't fall into the following catch-all Match Host * Banner /etc/ssh/refuse_msg DenyUsers *
用类似于geekosaur的方法,我最终得到了以下的解决scheme:(我需要的信息不是针对不同的主机,而是不同的用户,但它应该是相同的原理。)
Match User *,!user1,!user2,!root Banner /etc/ssh/refuse_msg ForceCommand echo
我没有得到ForceCommand来处理多个“匹配”行(就像在geekosaur的回答中一样),因为它总是使用ForceCommand,也许是因为没有“ForceCommand off”选项。
手册页说,匹配部分中的第一个语句“胜利”,但是因为之前的匹配语句不包含Banner或ForceCommand,所以使用最后的语句。 与横幅我可以使用“横幅/ dev / null”,但没有什么可以把ForceCommand …