vscode remote报错Waiting for server log

Monterey上

我在2025年8月,mac OS从Catalina升级到Monterey,软件更新到如下版本

  • macbook pro 2020 intel
  • Monterey(macOS 12.7.4)
  • VS Code=1.103.1,开启自动更新
  • Remote Development=0.26.0 ,它和它的子插件都开启自动更新
  • Remote - SSH=0.120.0,开启自动更新

问题:升级后,VS Code的Remote SSH仍无法连接服务器,报错与之前Catalina上的一样,详见

解决办法:我使用如下所有方法后,就能连接到服务器:

  • ⌘⇧P,然后输入 Remote-SSH: Kill VS Code Server on Host ,再输入服务器名称,回车:这个命令会杀死服务器上的VS Code 服务器进程(位于~/.vscode-server/中),然后重新连接时,VS Code 会尝试重新安装和启动服务器。

  • 服务器上mv ~/.vscode-server/ ~/vscode-server-back:删除.vscode-server/后,再次vscode远程连接服务器,会创建新的.vscode-server/,下载了和新版Remote-SSH匹配的服务器端程序。

  • 本地vscode设置:以下配置缺一不可。

    "remote.SSH.useExecServer": false,  // 连接到服务器时使用新的引导模式。如果出现连接问题,可关闭此模式
    "remote.SSH.useLocalServer": false, // 启用使用在窗口之间共享的单个连接和跨窗口重新加载进行连接的模式。这样可以更快地打开新窗口,并减少需要输入密码的次数
    "remote.SSH.connectTimeout": 60,    // 指定用于连接到远程的 SSH 命令的超时(以秒为单位)

Catalina上

现象及原因

我在2024、2025年,macbook pro 2020 intel+macOS Catalina上,VSCode>1.85连接CentOS7/Ubuntu18.04/Ubuntu20.04/Ubuntu22.04可能会无法连接,出现如下报错

Waiting for server log...

[00:26:32.554] Failed to parse remote port from server output
[00:26:32.554] Terminating local server
[00:26:32.569] Local server exit: 15
[00:26:32.846] Exec server for ssh-remote+g50 failed: Error
[00:26:32.846] Error opening exec server for ssh-remote+g50: Error

[15:53:18.927] Local server exit: 15
[15:53:21.045] Opening exec server for ssh-remote+g38
[15:53:21.566] Acquiring local install lock: /var/folders/wc/cp7yvqdn2n9dhfck78qf2_8m0000gn/T/vscode-remote-ssh-939ac7f5-install.lock
[15:53:21.567] Initizing new exec server for ssh-remote+g38
[15:53:21.731] Looking for existing server data file at /Users/mac/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-939ac7f5-384ff7382de624fb94dbaf6da11977bba1ecd427-0.115.0-es/data.json
[15:53:21.766] No existing data file
[15:53:21.767] Using commit id "384ff7382de624fb94dbaf6da11977bba1ecd427" and quality "stable" for server
[15:53:21.804] Opening exec server for ssh-remote+g38

网上查到可能的原因是:VSCode 1.86版本不再支持CentOS7(包括Ubuntu18.04等),因此需要手动回退至1.85版本

参考文章:

解决办法

  • 取消自动更新vscode:在本地vscode,按cmd+,,在设置页面搜索“Update: Mode”,将选项改为“none”。(要恢复自动更新,就改为default或start)image-20240924213656026

  • 安装vscode 1.85,下载链接:1.85版本,下载并安装它。

  • 打开vscode,在插件栏会看见,插件“Remote Development”及其下所有扩展包(包括插件“Remote - SSH”,负责vscode通过ssh连接远程服务器)的版本与vscode 1.85不适配。需要先卸载再重装插件“Remote Development”,而后“Remote Development”及其下所有扩展包都会重装为与vscode 1.85相适配的版本,即Remote Development 0.87.0。

  • 然后在vscode里连接远程服务器就会成功。

不建议的解决方法

升级glibc到2.28

参见Linux Prerequisites for Visual Studio Code Remote Development,vscode使用连接成功的前提是:

  • 对远程Linux系统通用的要求:需要 kernel >= 4.18(查看内核版本的命令cat /proc/version), glibc >=2.28 (查看版本的命令ldd --version), libstdc++ >= 3.4.25 (查看版本的命令strings /lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX), tar
  • 对Ubuntu>=20.04系统特别的要求:需要安装了libc6,libstdc++6,ca-certificates,tar (查看版本的命令apt show <软件名>

尽管我所登陆的服务器满足上述要求,但还是在macbook pro 2020 intel上,vscode连接Ubuntu20.04和ubuntu22的服务器均失败。我怀疑是其他原因,即vscode>1.85不支持macbook pro 2020 intel+macOS Catalina使用remote-SSH插件,或许需要升级macOS才能解决,又或许需要苹果芯片的电脑才能解决。我选择不升级操作系统,不买新电脑,而是把vscode降级到1.85,来解决这个问题。

引自VSCode>1.85不支持连接远程的CentOS7和Ubuntu18.04,升级glibc到2.28的方法无效:

参考Visual Studio Code Remote Development Frequently Asked Questions,将glibc更新至2.28。但重启后问题仍未解决。
尝试删除服务器上的.vscode-server,重新连接VSCode仍然无效。同时,删除客户端.ssh/known_hosts中的相关条目也未产生效果。

在Ubuntu18.04使用apt升级glibc到2.28的操作方法详见,该方法有安全隐患,不建议采用:

[!WARNING]

升级glibc可能会对系统稳定性产生影响,尤其是如果其他应用程序或库与新版本的glibc不兼容。在进行升级之前,请务必了解潜在的风险,并仔细考虑是否需要进行升级。

案例

我在2024年9月,在macbook pro 2020 intel上,vscode连接ubuntu18、Ubuntu20.04和ubuntu22的服务器,都无法连接成功,会遇到如下报错,完整报错详见本textbundle内的附件

[00:25:50.468] Log Level: 2
[00:25:50.583] SSH Resolver called for "ssh-remote+g50", attempt 1
[00:25:50.584] "remote.SSH.useLocalServer": true
[00:25:50.585] "remote.SSH.useExecServer": true
[00:25:50.585] "remote.SSH.path": undefined
[00:25:50.585] "remote.SSH.configFile": undefined
[00:25:50.586] "remote.SSH.useFlock": true
[00:25:50.586] "remote.SSH.lockfilesInTmp": false
[00:25:50.586] "remote.SSH.localServerDownload": auto
[00:25:50.586] "remote.SSH.remoteServerListenOnSocket": false
[00:25:50.586] "remote.SSH.showLoginTerminal": false
[00:25:50.587] "remote.SSH.defaultExtensions": []
[00:25:50.587] "remote.SSH.loglevel": 2
[00:25:50.587] "remote.SSH.enableDynamicForwarding": true
[00:25:50.591] "remote.SSH.enableRemoteCommand": false
[00:25:50.591] "remote.SSH.serverPickPortsFromRange": {}
[00:25:50.591] "remote.SSH.serverInstallPath": {}
[00:25:50.592] "remote.SSH.permitPtyAllocation": false
[00:25:50.592] "remote.SSH.preferredLocalPortRange: undefined
[00:25:50.592] "remote.SSH.useCurlAndWgetConfigurationFiles: false
[00:25:50.696] VS Code version: 1.93.1
[00:25:50.696] Remote-SSH version: remote-ssh@0.114.3
[00:25:50.696] darwin x64
[00:25:50.708] SSH Resolver called for host: g50
[00:25:50.708] Setting up SSH remote "g50"

...

> OS: Ubuntu 22.04.2 LTS x86_64
> Host: R4230-8G GPU
> Kernel: 5.15.0-119-generic
> Uptime: 18 days, 7 hours, 55 mins
> Packages: 1312 (dpkg), 4 (snap)
> Shell: bash 5.1.16
> Resolution: 1024x768
> Terminal: run-parts
> CPU: Intel Xeon Gold 6330 (112) @ 3.100GHz
> GPU: NVIDIA GeForce RTX 4090
> GPU: NVIDIA GeForce RTX 4090
> GPU: NVIDIA GeForce RTX 4090
> GPU: NVIDIA GeForce RTX 4090
> GPU: NVIDIA GeForce RTX 4090
> GPU: NVIDIA GeForce RTX 4090
> GPU: NVIDIA GeForce RTX 4090
> GPU: NVIDIA GeForce RTX 4090
> Memory: 306801MiB / 515601MiB
>
>
> zpool status:
>   all pools are healthy
>
> zpool usage:
>   datapool                       6% used out of 43.7T
>   [==================================================]
>
>   System information as of Tue Sep 24 00:25:57 CST 2024
>
>   System load:    20.70263671875    Processes:                1484
>   Usage of /home: 29.7% of 3.44TB   Users logged in:          3
>   Memory usage:   60%               IPv4 address for ens31f0: 166.111.153.129
>   Swap usage:     0%                IPv4 address for ens31f1: 192.168.0.2
>   Temperature:    53.0 C            IPv4 address for wg0:     10.0.0.150
> *** System restart required ***
> Ubuntu 18.04: jungpu[1-37] with nvidia-450, juncluster[1-4]
[00:25:58.819] > ready: b995d2eaba3e
[00:25:58.835] > Linux 5.15.0-119-generic #129-Ubuntu SMP Fri Aug 2 19:25:20 UTC 2024
[00:25:58.836] Platform: linux
[00:25:58.851] > /usr/bin/zsh
[00:25:58.851] Parent Shell: zsh
[00:25:58.851] Parent Shell pid: 4313
[00:25:58.917] > 4033820

...

> Spawned remote CLI: 4035866
[00:26:32.066] > Waiting for server log...
[00:26:32.097] > Waiting for server log...
[00:26:32.129] > Waiting for server log...
[00:26:32.162] > Waiting for server log...
[00:26:32.194] > Waiting for server log...
[00:26:32.227] > Waiting for server log...
[00:26:32.258] > Waiting for server log...
[00:26:32.290] > Waiting for server log...
[00:26:32.322] > Waiting for server log...
[00:26:32.354] > Waiting for server log...
[00:26:32.390] > Waiting for server log...
[00:26:32.419] > Waiting for server log...
[00:26:32.455] > Waiting for server log...
[00:26:32.485] > Waiting for server log...
[00:26:32.517] > Waiting for server log...
[00:26:32.550] > 60891db1baba: start
> listeningOn====
> osReleaseId==ubuntu==
> arch==x86_64==
> vscodeArch==x64==
> bitness==64==
> tmpDir==/run/user/10228==
> platform==linux==
[00:26:32.553] > unpackResult====
> didLocalDownload==0==
> downloadTime====
> installTime====
> serverStartTime==488==
> execServerToken==a1a1111a-111a-1aa1-a11a-a1aa11111a11==
> platformDownloadPath==cli-alpine-x64==
> 60891db1baba: end
[00:26:32.553] Received install output:
listeningOn====
osReleaseId==ubuntu==
arch==x86_64==
vscodeArch==x64==
bitness==64==
tmpDir==/run/user/10228==
platform==linux==unpackResult====
didLocalDownload==0==
downloadTime====
installTime====
serverStartTime==488==
execServerToken==a1a1111a-111a-1aa1-a11a-a1aa11111a11==
platformDownloadPath==cli-alpine-x64==

[00:26:32.554] Failed to parse remote port from server output
[00:26:32.554] Terminating local server
[00:26:32.569] Local server exit: 15
[00:26:32.846] Exec server for ssh-remote+g50 failed: Error
[00:26:32.846] Error opening exec server for ssh-remote+g50: Error

上述报错显示了服务器的登陆信息,说明本地vscode所使用的ssh config里指定的密钥对能登陆到服务器上,连接失败的原因可能是 VSCode>1.85不支持连接远程的CentOS7和Ubuntu18.04、Ubuntu20.04、Ubuntu22.04。

我把vscode降到1.85版本后,就能正常连接了。