You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code SSH连接Google Cloud卡OpenSSH行超时及主机密钥报错

VS Code连接GCP GPU实例SSH超时故障排查方案

故障现象

  • 连续一周使用Google Cloud GPU资源过程中,VS Code SSH连接频繁触发不同故障
  • 本次故障特征:VS Code发起SSH连接时不弹出密码输入提示,直接卡在stderr> OpenSSH_8.1p1, LibreSSL 2.7.3输出行,最终触发连接超时
  • 已尝试操作:更换Remote-SSH扩展版本、参考公开同类问题方案排查,均未修复
  • 对照验证:系统终端、浏览器内置SSH功能均可正常连接目标实例,仅VS Code连接异常

故障运行日志如下:

[10:29:22.090] Spawned 72151
[10:29:22.244] > local-server-1> Spawned ssh, pid=72168
[10:29:22.247] stderr> OpenSSH_8.1p1, LibreSSL 2.7.3 ***** THIS IS WHERE IT HANGS *****
[10:30:37.637] stderr> ssh: connect to host [address] port 22: Operation timed out
[10:30:37.638] > local-server-1> ssh child died, shutting down
[10:30:37.649] Local server exit: 0
[10:30:37.649] Received install output: local-server-1> Spawned ssh, pid=72168
OpenSSH_8.1p1, LibreSSL 2.7.3
ssh: connect to host [address] port 22: Operation timed out
local-server-1> ssh child died, shutting down

[10:30:37.653] Resolver error: Error: The operation timed out
    at Function.Offline (/Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:585270)
    at /Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:582907
    at Object.t.handleInstallOutput (/Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:583059)
    at Object.e [as tryInstallWithLocalServer] (/Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:624370)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:643503
    at async Object.t.withShowDetailsEvent (/Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:647221)
    at async /Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:622842
    at async T (/Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:619348)
    at async Object.t.resolveWithLocalServer (/Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:622457)
    at async Object.t.resolve (/Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:644831)
    at async /Users/[username]/.vscode/extensions/ms-vscode-remote.remote-ssh-0.82.1/out/extension.js:1:727005
[10:30:37.662] ------

根因确认

深入排查后确认故障由主机密钥校验失败触发,对应报错如下:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:[key].
Please contact your system administrator.
Add correct host key in /Users/[username]/.ssh/google_compute_known_hosts to get rid of this message.
Offending ECDSA key in /Users/[username]/.ssh/google_compute_known_hosts:6
ECDSA host key for compute.[nums] has changed and you have requested strict checking.
Host key verification failed.

GCP实例重启、重建后主机密钥会更新,VS Code Remote-SSH扩展的本地服务模式会吞掉SSH的主机密钥确认交互提示,既不弹出密钥确认窗口,也不弹出密码输入框,直接表现为卡在OpenSSH版本输出行直到超时。

修复步骤

  1. 清理失效旧密钥
    执行命令删除known_hosts文件中存储的对应实例旧密钥,替换命令中路径、主机名为你本地实际值:
    ssh-keygen -f "/Users/[username]/.ssh/google_compute_known_hosts" -R [实例对应的公网IP或compute.xxx主机标识]
    
    也可以手动打开/Users/[username]/.ssh/google_compute_known_hosts文件,直接删除报错提示中标注的第6行(即失效的ECDSA密钥行)。
  2. 写入新的合法主机密钥
    打开系统终端,正常执行SSH连接命令连接目标GCP实例:
    • 如果使用gcloud管理实例,执行gcloud compute ssh [你的实例名]
    • 如果直接用IP连接,执行ssh [登录用户名]@[实例公网IP]
      连接时终端会弹出新主机密钥确认提示,核对显示的SHA256指纹和之前报错中输出的新密钥指纹一致后,输入yes确认,新密钥会自动写入对应known_hosts文件。
  3. 验证VS Code连接
    回到VS Code重新发起Remote-SSH连接,此时会正常弹出身份验证提示,可正常建立连接。

若完成上述操作后仍卡住,打开VS Code设置搜索Remote.SSH: Use Local Server,临时关闭该选项后重试,部分0.8x版本的Remote-SSH扩展本地服务器模式存在吞交互提示的已知问题。

内容的提问来源于stack exchange,提问作者Jacques Thibodeau

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 23:09:24