是否可以在 Remote-SSH Visual Studio 代码中创建代理?

Is it possible to create a proxy in Remote-SSH Visual Studio Code?

我需要通过 Visual Studio 代码中的 REMOTE-SSH 连接到一台使用 ssh 的机器,但是从我之前通过 ssh 连接到的特定机器。

我可以毫无问题地连接到第一台机器,问题是当我登录第一台机器并尝试连接到第二台机器时它不允许我。我一直在寻找,但我只能找到展示如何只连接到一台机器而不通过另一台机器的示例。

感谢合作伙伴,我找到了一个解决方案,它包括稍微更改 ssh 的配置文件

因为我在 Windows 中使用 VS Code 并且我不想使用 netcat 我已经实现了下一个命令来创建代理:

Host <target-machine-name>
HostName <target-machine-ip>
User <user>
ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -q -x <proxy-machine-name> -W %h:22

希望它可以帮助其他人解决同样的问题。

如果您使用的是 macOS 并且想在 socks 代理下通过 ssh 连接到计算机 1.1.1.1:2222(127.0.0.1:1080),那么您可以使用以下配置:

Host 1.1.1.1
    HostName 1.1.1.1
        ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p 
    Port 2222
    User YourName

如果您正在使用 http 代理或使用 Windows(Linux),请查看 Connect with SSH through a proxy。然后替换对应的ProxyCommand.

希望对您有所帮助。