VS Code远程SSH连接失败,请求排查故障原因
问题
购买服务器后,使用VS Code的Remote-SSH扩展连接远程服务器时失败,错误日志如下:
[21:53:18.477] Got error from ssh: spawn C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe ENOENT [21:53:18.478] Checking ssh with "C:\WINDOWS\System32\OpenSSH\ssh.exe -V" [21:53:18.591] > OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2 [21:53:18.607] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 57363 "00.201.00.115" sh [21:53:18.615] Generated SSH command: 'type "C:\Users\PC\AppData\Local\Temp\vscode-linux-multi-line-command-91.201.52.115-422447103.sh" | "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 57363 "00.201.00.115" sh' [21:53:18.618] Using connect timeout of 17 seconds [21:53:18.623] Terminal shell path: C:\WINDOWS\System32\cmd.exe [21:53:19.478] > [21:53:19.485] Got some output, clearing connection timeout [21:53:21.790] > ssh: Could not resolve hostname haha: \335\362\356\362 \365\356\361\362 \35 > 5\345\350\347\342\345\361\362\345\355. > Попытка записи в несуществующий канал. [21:53:23.141] "install" terminal command done [21:53:23.143] Install terminal quit with output: Попытка записи в несуществующий канал. [21:53:23.144] Received install output: Попытка записи в несуществующий канал. [21:53:23.147] WARN: $PLATFORM is undefined in installation script output. Errors may be dropped. [21:53:23.150] Failed to parse remote port from server output [21:53:23.158] Resolver error: Error: at y.Create (c:\Users\PC\.vscode\extensions\ms-vscode-remote.remote-ssh-0.117.1\out\extension.js:2:739050) at t.handleInstallOutput (c:\Users\PC\.vscode\extensions\ms-vscode-remote.remote-ssh-0.117.1\out\extension.js:2:737131) at t.tryInstall (c:\Users\PC\.vscode\extensions\ms-vscode-remote.remote-ssh-0.117.1\out\extension.js:2:854138) at async c:\Users\PC\.vscode\extensions\ms-vscode-remote.remote-ssh-0.117.1\out\extension.js:2:812962 at async t.withShowDetailsEvent (c:\Users\PC\.vscode\extensions\ms-vscode-remote.remote-ssh-0.117.1\out\extension.js:2:816213) at async R (c:\Users\PC\.vscode\extensions\ms-vscode-remote.remote-ssh-0.117.1\out\extension.js:2:809499) at async t.resolve (c:\Users\PC\.vscode\extensions\ms-vscode-remote.remote-ssh-0.117.1\out\extension.js:2:813614) at async c:\Users\PC\.vscode\extensions\ms-vscode-remote.remote-ssh-0.117.1\out\extension.js:2:1099250 [21:53:23.310] ------
已尝试重新安装VS Code、Remote-SSH扩展及修改Remote-SSH设置,问题仍未解决,需排查故障原因。
排查方案
1. 修正SSH配置中的主机名错误
日志明确提示Could not resolve hostname haha,说明VS Code的SSH配置里错误设置了主机名为haha,而非实际服务器IP00.201.00.115:
- 打开VS Code,按
F1输入Remote-SSH: Open SSH Configuration File,选择用户或系统配置文件 - 找到对应服务器的配置块,确保
HostName字段对应正确的服务器IP/域名,示例:Host my-server HostName 00.201.00.115 User your-server-username - 保存配置后重新尝试连接
2. 强制指定OpenSSH路径
日志开头显示找不到PowerShell目录下的ssh.exe,但系统已安装OpenSSH,需让VS Code明确使用正确的SSH路径:
- 打开VS Code设置(快捷键
Ctrl+,),搜索remote.SSH.path - 将值设置为
C:\WINDOWS\System32\OpenSSH\ssh.exe - 重启VS Code后重试连接
3. 测试基础SSH连通性
跳过VS Code,直接在本地终端测试SSH连接,排除网络或服务器端问题:
- 打开CMD或PowerShell,执行命令:
ssh your-server-username@00.201.00.115 - 如果连接失败,排查以下点:
- 服务器防火墙是否开放22端口
- 服务器SSH服务是否正常运行(执行
systemctl status sshd验证) - 本地网络是否能ping通服务器IP
- 若终端能正常连接,再回到VS Code使用Remote-SSH重试
4. 清理VS Code远程缓存
缓存损坏可能导致异常,清理后重新初始化:
- 关闭VS Code,删除以下目录:
C:\Users\PC\.vscode\extensions\ms-vscode-remote.remote-ssh-0.117.1(对应你的扩展版本)C:\Users\PC\.ssh\vscode-ssh-remote
- 重新安装Remote-SSH扩展后重试连接
内容的提问来源于stack exchange,提问作者user27780899
相关产品推荐
相关产品推荐

