配置中的反向 ssh 隧道

Pra*_*tic 19 ssh configuration ssh-tunneling

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

我正在尝试重现此命令

ssh -R 55555:localhost:22 user@host
Run Code Online (Sandbox Code Playgroud)

在我的 .ssh/config 文件中,这样当我输入时,ssh host我会以用户身份和反向隧道通过 ssh 连接到主机。配置文件接受的命令是命令行标志的更详细的对应物。根据 ssh 手册页和 ssh_config 手册页,似乎相应的设置是 BindAddress。

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

Host host
     Hostname host
     User user
     BindAddress 55555:localhost:22
Run Code Online (Sandbox Code Playgroud)

当我尝试时,这个和轻微的变化导致连接被拒绝

ssh localhost -p 55555
Run Code Online (Sandbox Code Playgroud)

一旦登录到主机。如果我在第一次 SSH 到主机时在顶部明确给出命令,同样的工作正常。我的配置文件在没有反向隧道命令的情况下也能工作;ssh host我以用户身份登录到主机。

Mar*_*rco 42

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.
Run Code Online (Sandbox Code Playgroud)

相当于的配置文件-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. [...]
Run Code Online (Sandbox Code Playgroud)

有了这些信息,命令行

ssh -R 55555:localhost:22 user@host
Run Code Online (Sandbox Code Playgroud)

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

Host host
HostName host
User user
RemoteForward 55555 localhost:22
Run Code Online (Sandbox Code Playgroud)