配置中的反向SSH隧道


16

如何使用./ssh/config文件建立反向ssh隧道?

我正在尝试重现此命令

ssh -R 55555:localhost:22 user@host

在我的.ssh / config文件中,这样当我键入内容时,ssh host我将以用户身份并通过反向隧道将ssh发送到主机。配置文件接受的命令与命令行标志更为冗长。基于ssh联机帮助页和ssh_config的联机帮助页,似乎相应的设置为BindAddress。

在我的.ssh / config文件中,我有:

Host host
     Hostname host
     User user
     BindAddress 55555:localhost:22

这以及它的细微变化会导致我尝试连接时被拒绝

ssh localhost -p 55555

一旦登录到主机。如果我在第一次将主机切入主机时在顶部显式给出命令,则同样可以正常工作。我的配置文件无需反向隧道命令即可工作;ssh host以用户身份登录到主机。

Answers:


29

BindAddress不是您追求的选择。来自man ssh_config

BindAddress
         Use the specified address on the local machine as the source
         address of the connection.  Only useful on systems with more than
         one address.

等效的配置文件-RRemoteForward

RemoteForward
         Specifies that a TCP port on the remote machine be forwarded over
         the secure channel to the specified host and port from the local
         machine.  The first argument must be [bind_address:]port and the
         second argument must be host:hostport. [...]

有了此信息,命令行

ssh -R 55555:localhost:22 user@host

转换为以下.ssh/config语法:

Host host
HostName host
User user
RemoteForward 55555 localhost:22
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.