解决windows端vscode通过跳板机连接远程服务器

最开始这样写:

  HOST jumpServer
      HostName xx.xx.xx.xx
      User xx

  HOST targetServer
      HostName xx.xx.xx.xx
      User xx
      ProxyCommand ssh -W %h:%p jumpServer

报错提示:CreateProcessW failed error:2 posix_spawn: No such file or directory
发现是Windows openSSH 软件包的问题。
在 ProxyCommands 中,它请求完整的路径限定符,但最好在此处使用正斜杠!
于是改为

HOST targetServer
    HostName xx.xx.xx.xx
    User xx
    ProxyCommand C:/Windows/System32/OpenSSH/ssh.exe -W %h:%p jumpServer

结果出现了新的错误: vscode ssh: Could not resolve hostname: \262\273\326\252\265\300\...
似乎是ssh命令处理中文字符有些问题,并且把配置文件Server当作了一个域名。系统语言切换到英语之后这些打印就很正常了,但是配置文件依旧不能正确读取。
怀疑是不是系统里的ssh命令被替换过了, 使用这套程序所有的中文打印都是乱码。

全局搜索ssh.exe之后发现git自带有一个ssh,于是将路径替换为git的ssh:

HOST targetServer
    HostName xx.xx.xx.xx
    User xx
    ProxyCommand C:/Program Files/Git/usr/bin/ssh.exe -W %h:%p jumpServer

成功访问!

参考文章:https://zhuanlan.zhihu.com/p/81039716?from_voters_page=true
https://stackoverflow.com/questions/65059250/ssh-and-scp-failed-with-createprocessw-failed-error2-posix-spawn-no-such-file

posted @ 2022-02-19 11:35  Jerome12138  阅读(2126)  评论(0编辑  收藏  举报