如何限制传出的SSH通信只有特定的主机W / O的iptables

我们的一个SSH服务器作为jumphost。 用户只能进入某些目标主机。 这可以用iptables来完成,但目前这不是所需的解决scheme。

我检查了man ssh_config ,看看是否可以在系统范围内configurationssh_config ,但没有发现提示。

除了iptables有什么想法来实现这个吗?

添加一个有效的路由到你的目标和一个更通用的路由为null。 然后,只有定义到您的目标的路线将可供用户使用。 问题是这是所有的用户可用

你可以使用这样的东西

 #! /bin/sh MSG='******************************** 1 = host1 2 = anotherhost 3 = host3 0 = exit ********************************' host=none while test none = "$host" do echo "$MSG" echo -n 'your choice: ' read choice case "$choice" in 1) host=host1.domain.com;; 2) host=anotherhost.xy.de;; 3) host=just.go.here;; 0) exit;; esac done ssh $host 

作为你的ssh用户在jumphost上的loginshell。 如果将其保存为/ usr / bin / ssh-choice,请不要忘记将/ usr / bin / ssh-choice添加到/ etc / shells中。

TomTomTom

我不知道有关设置,但也许禁用跳转主机上的shelllogin,并允许端口转发到特定的用户只有特定的用户,然后锻炼-J选项(ProxyJump)的OpenSSH可能是一个解决scheme吗? sshd_config的Match指令可能对此有所帮助。

回应先前的评论:

如果您需要shell访问,那么您可能需要在用户的主目录中不可变且空的.ssh / config,在/ etc / ssh / ssh_config中列出所有允许的主机,并捕获所有redirect到总是失败的ProxyCommand的Host指令也打印教练信息到stderr,所以用户可以看到它)。

沿线的东西:

 Host host1 host1.example.com <whatever directives may be needed here if any> Host host2 host2.example.net <whatever directives may be needed here if any> Host * ProxyCommand /bin/false 

从主机的路由表中删除所有内容,或者放置防止主机本身之外的连接的防火墙。

你可以在目标机器上hosts.allow和/或hosts.deny。