基于用户的ssh端口转发

我只想为用户git转发端口22(ssh)到端口7999(其中bitbucket正在运行),并为其他用户使用正常的sshd。 我查看了HAProxy的ssh转发,但这并不能让我区分每个用户。

我如何在服务器上configuration它? 我不希望每个客户端ProxyCommand在其.ssh/configconfigurationProxyCommand

我不认为你可以做到这一点,因为用户不知道什么时候连接是最初创build的,当你需要redirect。

你知道吗,每个用户~/.ssh/config中的任何东西都可以放在/etc/ssh/ssh_config文件中并全局应用? 也许你可以用它来全局configuration一个ProxyCommand

你可以尝试沿着这条线(未经testing):

/etc/ssh/sshd_config (或类似的),添加如下所示:

 Match user git ForceCommand ssh git@localhost -p 7999 

不要忘记重新加载/重新启动sshd 。 这应该“隧道”连接到端口ForceCommand nc localhost 7999上的Bitbucket。或者,一个netcat也可以工作( ForceCommand nc localhost 7999 )。

正如我所说,这是未经testing,但它的作品,我redirect到另一个主机的SSH连接完全。