配置中的反向 ssh 隧道

配置中的反向 ssh 隧道

如何使用 ./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

一旦登入主機上。如果我在第一次 sshing 到主機時在頂部明確給出命令,同樣可以正常工作。我的設定檔在沒有反向隧道命令的情況下也可以工作;ssh host我以使用者登入主機。

答案1

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

相關內容