使用 SSH 隧道接受传入连接

Using an SSH tunnel to accept incoming connections

我正在尝试使用 SSH 隧道完成一些事情,但我尝试使用谷歌搜索 "SSH tunneling" 并发现了关于各种不同场景的讨论,但不是我的场景。

我在计算机 A 上工作。我可以通过 SSH 访问计算机 B。我希望计算机 B 运行 程序 X 需要连接到计算机 A 上的端口 40000。问题是,计算机 B 有严酷的防火墙应用于它,我不想修改。我想要的是利用我的能力轻松地通过 SSH 从计算机 A 连接到计算机 B,使从 B 到 A 的连接成为可能。

这就是我的设想:我在计算机 A 上 运行 的程序 Y,它通过 SSH 连接到计算机 B,然后在计算机 B 上侦听端口 40000 上的连接,并且通过 SSH 连接将它们转发到计算机 A 上的端口 40000。然后我在计算机 B 上配置程序 X 以尝试连接到计算机 B 上的端口 40000,然后它实际上连接到计算机 A 上的端口 40000。

是否有执行此操作的现有程序/SSH 方法?

我猜您正在寻找 ssh 的 -R 选项:

 -R [bind_address:]port:host:hostport
         Specifies that the given port on the remote (server) host is to be
         forwarded to the given host and port on the local side.  This works
         by allocating a socket to listen to port on the remote side, and
         whenever a connection is made to this port, the connection is for-
         warded over the secure channel, and a connection is made to host
         port hostport from the local machine.
         [...]