解決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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM