vscode remote报错Waiting for server log

现象及原因

VSCode>1.85连接CentOS7/Ubuntu18.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

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

参考文章:

解决办法

  • 取消自动更新vscode:在本地vscode,按cmd+,,在设置页面搜索“Update: Mode”,将选项改为“none”:image-20240924213656026

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

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

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

不建议的解决方法

升级glibc到2.28

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

  • 对远程Linux系统通用的要求:需要 kernel >= 4.18, glibc >=2.28, libstdc++ >= 3.4.25, tar
  • 对Ubuntu>=20.04系统特别的要求:需要安装了libc6,libstdc++6,ca-certificates,tar

引自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上,访问ubuntu18和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、Ubuntu22.04。

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