Visual Studio 代码通过 ssh 代理远程 ssh

han*_*nan 6 ssh remote-debugging visual-studio-code

我正在尝试使用 vs-code 的remote-ssh 扩展通过 ssh 隧道连接到服务器。服务器是没有公共 IP 地址的内部集群的一部分,我使用链接中概述的方法通过集群中的代理连接到它:

# ~/.ssh/config
Host internal*
User root
ProxyCommand ssh user@firewall 'nc %h %p'
Run Code Online (Sandbox Code Playgroud)

当我尝试连接到内部服务器时,出现以下错误对话框:

无法建立与“内部服务器”的连接。该进程试图写入一个不存在的管道。

输出窗口的日志:

remote-ssh@0.45.6
win32 x64
SSH Resolver called for "ssh-remote+internal-server", attempt 1
SSH Resolver called for host: internal-server
Setting up SSH remote "internal-server"
Using commit id "........" and quality "stable" for server
Testing ssh with ssh -V
ssh exited with code: 0
Got stderr from ssh: OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
Running script with connection command: ssh -o ClearAllForwardings=true internal-server bash
Install and start server if needed
> 
Got some output, clearing connection timeout
> ]0;C:\WINDOWS\SYSTEM32\cmd.exe
> 
> CreateProcessW failed error:2
> 
> posix_spawn: No such file or directory
> The process tried to write to a nonexistent pipe.
> 
"install" terminal command done
Install terminal quit with output: The process tried to write to a nonexistent pipe.
Received install output: The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe
TELEMETRY: {"eventName":"resolver","properties":{"outcome":"failure","reason":"OfflineError"},"measures":{"resolveAttempts":1,"retries":1}}
------
Run Code Online (Sandbox Code Playgroud)

如何使用 vs-code 的 remote-ssh 连接到代理/防火墙后面的计算机?

Jun*_*eng 7

对于遇到相同问题的任何人,我通过提供 ssh 的绝对位置来解决它,例如:

ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -W %h:%p server
Run Code Online (Sandbox Code Playgroud)

  • 我在哪里添加它?在远程 ssh 配置中? (3认同)

inf*_*ner 0

到目前为止我已经探索过可能有两个原因。

  1. 由于 ssh 文件的配置错误/冲突,您遇到此错误。对我有用的是,我有目录“C:\Users\gur51262”,它具有 ssh 配置,但还有另一个目录在路径“C:\ProgramData\ssh”上也有文件“ssh_config”,这可能是与之产生冲突。

因此,我只配置了此路径“C:\Users\gur51262”上存在的文件,并且省略了路径“C:\ProgramData\ssh”上存在的其他文件的内容。

还要确保您遵循配置文件的语法(如果有)。喜欢

Host host203
  HostName 172.19.51.203
  User root 
Run Code Online (Sandbox Code Playgroud)

解决方案适用于windows7。

  1. “.ssh/config”文件中可能存在冲突。可能存在重复的主机名条目,如下所示

    Host 172.19.51.212
      HostName 172.19.51.212
    Host 172.19.51.212
      HostName 172.19.51.212
      User root
    
    Run Code Online (Sandbox Code Playgroud)