问题描述:
远程连vscode出现报错,但是连接xftp反而可以正常运行,说明vscode有问题
报错如下:
[01:54:38.607] Got error from ssh: spawn C:\Program Files (x86)\VMware\VMware Workstation\bin\ssh.exe ENOENT
[01:54:38.607] Checking ssh with "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\ssh.exe -V"
[01:54:38.609] Got error from ssh: spawn C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\ssh.exe ENOENT
[01:54:38.609] Checking ssh with "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\libnvvp\ssh.exe -V"
[01:54:38.610] Got error from ssh: spawn C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\libnvvp\ssh.exe ENOENT
[01:54:38.611] Checking ssh with "C:\Windows\system32\ssh.exe -V"
[01:54:38.613] Got error from ssh: spawn C:\Windows\system32\ssh.exe ENOENT
[01:54:38.613] Checking ssh with "C:\Windows\ssh.exe -V"
[01:54:38.614] Got error from ssh: spawn C:\Windows\ssh.exe ENOENT
[01:54:38.615] Checking ssh with "C:\Windows\System32\Wbem\ssh.exe -V"
[01:54:38.617] Got error from ssh: spawn C:\Windows\System32\Wbem\ssh.exe ENOENT
[01:54:38.617] Checking ssh with "C:\Windows\System32\WindowsPowerShell\v1.0\ssh.exe -V"
[01:54:38.620] Got error from ssh: spawn C:\Windows\System32\WindowsPowerShell\v1.0\ssh.exe ENOENT
[01:54:38.620] Checking ssh with "C:\Windows\System32\OpenSSH\ssh.exe -V"
[01:54:38.680] > OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2
[01:54:38.688] Running script with connection command: "C:\Windows\System32\OpenSSH\ssh.exe" -T -D 1798 "dgx2" sh
[01:54:38.690] Generated SSH command: 'type "C:\Users\usr\AppData\Local\Temp\vscode-linux-multi-line-command-dgx2-605320821.sh" | "C:\Windows\System32\OpenSSH\ssh.exe" -T -D 1798 "dgx2" sh'
[01:54:38.691] Using connect timeout of 17 seconds
[01:54:38.693] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[01:54:38.988] > ]0;C:\WINDOWS\System32\cmd.exe
[01:54:38.989] Got some output, clearing connection timeout
[01:54:39.010] > Bad permissions. Try removing permissions for user: NT AUTHORITY\\Authenticated
> Users (S-1-5-11) on file C:/ProgramData/ssh/ssh_config.
> Bad owner or permissions on __PROGRAMDATA__\\ssh/ssh_config
> 过程试图写入的管道不存在。
[01:54:41.095] "install" terminal command done
[01:54:41.095] Install terminal quit with output: 过程试图写入的管道不存在。
[01:54:41.096] Received install output: 过程试图写入的管道不存在。
[01:54:41.096] Failed to parse remote port from server output
[01:54:41.099] Resolver error: Error:
at v.Create (c:\Users\usr\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.0\out\extension.js:2:493431)
at t.handleInstallOutput (c:\Users\usr\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.0\out\extension.js:2:490753)
at t.tryInstall (c:\Users\usr\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.0\out\extension.js:2:608797)
at async c:\Users\usr\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.0\out\extension.js:2:568008
at async t.withShowDetailsEvent (c:\Users\usr\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.0\out\extension.js:2:571256)
at async P (c:\Users\usr\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.0\out\extension.js:2:564794)
at async t.resolve (c:\Users\usr\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.0\out\extension.js:2:568667)
at async c:\Users\usr\.vscode\extensions\ms-vscode-remote.remote-ssh-0.115.0\out\extension.js:2:839059
原因分析:
之前连过该ip对应的服务器,vscode本地(win本地)已经保存了该ip对应服务器的密钥,重置服务器
之后的 SSH 主机密钥(host key) 发生了变化。即使你的用户密码或私钥没有改变,SSH 的身份验证机制依然依赖于服务器的主机密钥来确保你连接的服务器没有被中途篡改。
解决方案:
删除旧的 known_hosts 条目: 如果你确认这是同一台服务器,只是因为某些原因密钥不一致,你可以手动删除 known_hosts 文件中关于该服务器的旧条目。操作步骤如下:
打开命令提示符:输入
ssh-keygen -R [服务器的IP地址] # 比如ssh-keygen -R 192.168.1.100
这样会从 ~/.ssh/known_hosts 文件中删除该服务器的记录。尝试重新通过 VSCode 连接远程服务器。这个时候vscode系统会提示你重新接受服务器的密钥:
The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxx...
Are you sure you want to continue connecting (yes/no)?
yes之后输入密码即可。
或者更简单,直接在win下删掉C:\用户\user_name.ssh\known_hosts中的known_hosts文件即可。