通过中间主机安全地隧道端口

Naf*_*Kay 25 ssh port-forwarding

我希望将 VNC 的端口路由回我的家。我必须跳过单个主机才能跳转到我的实际工作机器。

  • sittinghere 将是我本地的家用机器
  • hopper 将通过我需要做的中间跳跃
  • overthere 将是远程工作机器

我可以这样做以通过 SSH 连接到我的工作机器:

ssh -t hopper "ssh -t overthere"
Run Code Online (Sandbox Code Playgroud)

我想使用端口转发将远程端口 5900 转发overthere到本地端口 5900 上sittinghere。但是,我希望能够在不公开绑定到端口的情况下执行此操作,hopper因为该机器上的任何人都可以连接到我的 VNC 连接。

有什么方法可以让我安全地将该端口转发到我的本地机器,而没有人能够访问它hopper

Cre*_*eek 23

使用 SSH 的本机功能来转发端口。从sittinghere执行:

 ssh -v -N -L 5900:overthere:5900 user@hopper
Run Code Online (Sandbox Code Playgroud)

将您的 VNC 客户端指向localhost:5900,流量将overthere:5900通过建立在hopper

  • AFAIK,如果 5900 仅绑定在本地(127.0.0.1)接口上,则此解决方案将无济于事,因为隧道发生在“hopper”上,然后“hopper”将所有流量转发到“overthere:5900”。如果`overthere:5900` 在`0.0.0.0` 或给定的接口上监听,那么它会工作,但如果它在`127.0.0.1` 上监听就不行。 (2认同)

Naf*_*Kay 20

我最终使用了一些 SSH~/.ssh/config技巧来实现这一点:

Host hopper
    User naftuli
    ForwardAgent yes

Host overthere
    User naftuli
    ForwardAgent yes
    ProxyCommand ssh -q hopper nc overthere 22
Run Code Online (Sandbox Code Playgroud)

这样做的作用是,当我尝试连接ssh overtherefrom 时sittinghere,它会连接到hopperSSH 连接,然后将 SSH 连接代理到端口 22 on overthere(即: SSH on overthere)。

这有一些很棒的副作用:

ssh -L 5900:localhost:5900 overthere "x11vnc -display :0 -localhost"
Run Code Online (Sandbox Code Playgroud)

一切都很棒,据我所知,5900 没有在 上打开hopper,只是直接从 转发overtheresittinghere