【VScode】Remote-SSH XHR failed无法访问远程服务器

问题概述

当使用VScode连接远程服务器时,往往需要使用Remote-SSH这个插件。而该插件有一个小bug,当远程服务器网络不佳时容易出现。

在控制台会出现下述语句:

复制代码
Resolver error: Error: XHR failed at y.onerror (vscode-file://vscode-app/d:/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:77:1261)

原因与解决方法

原因

该插件在连接远程服务器时,插件会在服务器端自动运行一个脚本。该脚本的主要内容是检查服务器的vscode-server的运行情况,若服务器端不能运行,则会自动下载。而当服务器网络不佳时,下载往往会超时,导致连接失败。

解决方法

懂了报错的原因,那就可以从中找出解决方法。即手动在本地下载安装包,然后手动传到服务器端。这样是可以解决这个问题的,虽然不是很优雅。

步骤

  1. 通过其他SSH等方式(如:Xshell),进入远程服务器的Terminal。

  2. 在服务器端,进入下面的目录,获取commit id。

    bash 复制代码
    $ ls ~/.vscode-server/bin
    2ccd690cbff1569e4a83d7c43d45101f817401dc

    在这里,我的commit id就是2ccd690cbff1569e4a83d7c43d45101f817401dc。

  3. 手动下载出问题的包(tarball),注意下面的COMMIT_ID要替换成自己在上一步得到的commit id。

    如我的稳定版链接就是:https://update.code.visualstudio.com/commit:2ccd690cbff1569e4a83d7c43d45101f817401dc/server-linux-x64/stable

  4. 下载后会得到一个vscode-server-linux-x64.tar.gz,将其通过sftp等方式传到服务器上。路径:~/.vscode-server/bin/COMMIT_ID/vscode-server-linux-x64.tar.gz

  5. 在服务器端进入该路径,解压。

bash 复制代码
$ cd ~/.vscode-server/bin/$COMMIT_ID
$ tar -xvzf vscode-server-linux-x64.tar.gz --strip-components 1
  1. 重新使用VScode进行连接。

参考:

1\] https://stackoverflow.com/questions/56718453/using-remote-ssh-in-vscode-on-a-target-machine-that-only-allows-inbound-ssh-co \[2\] https://github.com/microsoft/vscode-remote-release/issues/2792 \[3\] https://github.com/microsoft/vscode-remote-release/issues/3349

相关推荐
元清加油3 小时前
【Golang】:函数和包
服务器·开发语言·网络·后端·网络协议·golang
任磊abc5 小时前
vscode无法检测到typescript环境解决办法
ide·vscode·typescript
hfut02885 小时前
【vscode使用说明】
vscode·编辑器·vim
向日葵.6 小时前
fastdds.ignore_local_endpoints 属性
服务器·网络·php
weixin_307779137 小时前
VS Code配置MinGW64编译GNU 科学库 (GSL)
开发语言·c++·vscode·算法
昵称为空C8 小时前
SpringBoot接口限流的常用方案
服务器·spring boot
Peter_Deng.8 小时前
Linux 下基于 TCP 的 C 语言客户端/服务器通信详解(三个示例逐步进阶)
服务器·c语言·网络
ala咪9 小时前
切换VSCODE 中的默认 shell
vscode
BIBI204910 小时前
自定义 VSCode 标题栏以区分不同版本
ide·vscode·编辑器
檀越剑指大厂13 小时前
【Linux系列】如何在 Linux 服务器上快速获取公网
linux·服务器·php