【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

相关推荐
源远流长jerry1 小时前
Linux 网络虚拟化深度解析:从 veth 设备对到容器网络实战
linux·运维·服务器·网络·性能优化·php
bupt_011 小时前
Hermes深入理解及源码解析(二):Hermes的记忆机制
java·服务器·前端
kidwjb1 小时前
Linux共享内存
linux·服务器·进程间通信
QuestLab2 小时前
Ollama在Linux上安装的详细记录
linux·运维·服务器
IT瑞先生2 小时前
Linux系统基础
linux·运维·服务器
jieyucx2 小时前
Go语言通透教程:结构体定义与方法
服务器·数据库·golang·结构体
renren-1002 小时前
centos7.9 升级openssl11 导致的系统命令瘫痪
linux·运维·服务器
金玉满堂@bj3 小时前
Pytest 完整使用教程
运维·服务器·pytest
SWAGGY..3 小时前
Linux系统编程:(六)编译器gcc/g++
linux·运维·服务器
蜡笔婧萱3 小时前
Linux——Web服务器网址建立(http和https的分离)
linux·运维·服务器