简体   繁体   English

VS code remote x11 在连接到远程服务器时无法显示

[英]VS code remote x11 cant get DISPLAY while connecting to remote server

I use Windows VS code and this extensions "Remote SSH", "Remote X11", "Remote X11 (SSH)" to connect and to get graphics from remote server.我使用 Windows VS 代码和此扩展“远程 SSH”、“远程 X11”、“远程 X11 (SSH)”来连接并从远程服务器获取图形。

I run VcXsrv, Pageant.我运行 VcXsrv,选美。 X11 forwarding works if I connect with Pageant directly.如果我直接与 Pageant 连接,X11 转发工作。 It even works in VS code terminal if I set "export DISPLAY=localhost:10.0" in remote server.如果我在远程服务器中设置“export DISPLAY=localhost:10.0”,它甚至可以在 VS 代码终端中使用。 So all works besides Remote X11, it cant set DISPLAY variable, with this log: Failed to get DISPLAY: Error: Invalid cygwin unix socket path所以除了远程 X11 之外的所有工作,它无法设置 DISPLAY 变量,使用此日志:无法获取显示:错误:无效的 cygwin unix 套接字路径

Reproduced from zhuanlan.zhihu.com see comment above.转载自 zhuanlan.zhihu.com 见上文评论。 Basically, all we need to know is that on the server side (mostly are Linux OSs), they use X11 protocol to display GUI.基本上,我们只需要知道在服务器端(主要是 Linux 操作系统),它们使用 X11 协议来显示 GUI。

IMHO, the X11 protocol is consists of two parts, the XServer and the XClient.恕我直言,X11 协议由两部分组成,XServer 和 XClient。 XServer is the one who actually draws the pixels on display equipment, while the XClient takes charge of processing the logics behind displaying. XServer 是实际在显示设备上绘制像素的那个,而 XClient 负责处理显示背后的逻辑。

To show GUI from remote server, we need to use a tech called X11 Forwarding, which means forwarding the remote XClient's stuff to the XServer that runs on the local machine.要从远程服务器显示 GUI,我们需要使用一种称为 X11 转发的技术,这意味着将远程 XClient 的内容转发到在本地机器上运行的 XServer。

  1. VS Code Configuration Step 1.1: Install VS Code Step 1.2: Install Remote-SSH plugin VS Code 配置步骤 1.1:安装 VS Code 步骤 1.2:安装 Remote-SSH 插件

在此处输入图像描述

  1. Client Machine Configuration (Windows) Step 2.1: Modify config file The config file is used by SSH.客户端机器配置(Windows) 步骤 2.1:修改配置文件 配置文件由 SSH 使用。 It locates at C:\Users\[user]\.ssh\config , where [user] should be your username.它位于C:\Users\[user]\.ssh\config ,其中[user]应该是您的用户名。

To establish a key-based SSH connection, you should specify the path of key file.建立基于密钥的SSH连接,需要指定密钥文件的路径。 What's more, to enable X11 Forwarding, the following two lines should be added to config file:此外,要启用 X11 转发,需要在配置文件中添加以下两行:

ForwardX11 yes
ForwardX11Trusted yes

在此处输入图像描述 example of config file配置文件示例

Step 2.2: Download & install VcXsrv Download VcXsrv from here: VcXsrv Windows X Server download |步骤 2.2:下载并安装 VcXsrv 从这里下载 VcXsrv:VcXsrv Windows X 服务器下载 | SourceForge.net SourceForge.net

After the installation, the following software should appear in your Menus.安装后,以下软件应出现在您的菜单中。 This is exactly the XServer we need.这正是我们需要的 XServer。

在此处输入图像描述

  1. Server Machine Configuration (Ubuntu) Remember to copy your public key into the authorized_keys on your server machine if you configure a key-based SSH connection.服务器机器配置 (Ubuntu) 如果您配置基于密钥的SSH连接,请记住将您的公钥复制到服务器机器上的authorized_keys中。

Step 3.1: Get $DISPLAY Usually, the $DISPLAY variable is set by default.步骤 3.1:获取$DISPLAY通常, $DISPLAY变量是默认设置的。 So, type the following command in your server's terminal, and it will output something in the form of IP:DS Remember the D 's value, which is 10 here.因此,在您的服务器终端中键入以下命令,它将 output 形式为IP:DS记住D的值,这里是10

> echo $DISPLAY
localhost:10.0

If the output is blank, you should set the $DISPLAY value by yourself.如果 output 为空白,则应自行设置$DISPLAY值。

export DISPLAY=localhost:10.0 
  1. Workflow / Pipeline Step 4.1: Run VcXsrv Display number should be the value you get from Step 3.1, here I set it as 10 .工作流程/管道步骤 4.1:运行VcXsrv Display number应该是您从步骤 3.1 获得的值,这里我将其设置为10 在此处输入图像描述

Tick Disable access control勾选Disable access control

在此处输入图像描述

There should be an 'X' icon on your task bar when you run the software successfully.成功运行软件后,任务栏上应该会出现一个'X'图标。

在此处输入图像描述

Step 4.2: Run VS Code & connect to the server Check the value of $DISPLAY , it should be consistent with your before setting.步骤 4.2:运行 VS Code 并连接到服务器 检查$DISPLAY的值,它应该与您之前设置的一致。

Then type the command:然后输入命令:

xeyes

If the GUI of two eyes shows up, it means you make it!如果出现两只眼睛的GUI ,就说明你成功了!

在此处输入图像描述

Step 4.3: Test your own GUI program (optional) You can even run your self-written GUI , pretty cool huh?步骤 4.3:测试您自己的GUI程序(可选)您甚至可以运行您自己编写的GUI ,很酷吧?

在此处输入图像描述

I found the solution to this here https://github.com/microsoft/vscode-remote-release/issues/4600 .我在这里找到了解决方案https://github.com/microsoft/vscode-remote-release/issues/4600 I am summarizing the steps here, since the steps are not very clear there.我在这里总结了这些步骤,因为那里的步骤不是很清楚。 Before you start make sure you have one of the recent versions of VScode (I am using 1.55.2).在开始之前,请确保您拥有最新版本的 VScode 之一(我使用的是 1.55.2)。

Steps to connect from Windows to Linux:从 Windows 连接到 Linux 的步骤:

  1. Install Xming (Should also work with VcXsrv).安装 Xming(也应该与 VcXsrv 一起使用)。 Start Xming (Default Display:0.0)启动 Xming(默认显示:0.0)
  2. Install Remote-SSH.安装远程 SSH。 You don't need the other extensions.您不需要其他扩展。 Nor do you need a running terminal with active x11 connection.您也不需要具有活动 x11 连接的正在运行的终端。
  3. Add a new environment variable to Windows: DISPLAY = localhost:0.0 (Adjust this according to your Xming setting. I prefer the default value).向 Windows 添加一个新的环境变量: DISPLAY = localhost:0.0 (根据您的 Xming 设置调整此值。我更喜欢默认值)。
  4. Connect remotely using VScode.使用 VScode 远程连接。 Make sure that the ssh config forwards x11 connection: ForwardAgent yes ForwardX11 yes ForwardX11Trusted yes You can actually check the logs of remote host, if x11 forwarding is successful and port is set.确保 ssh 配置转发 x11 连接: ForwardAgent yes ForwardX11 yes ForwardX11Trusted yes如果 x11 转发成功并且端口已设置,您可以实际检查远程主机的日志。 If not set properly, it will complain that the display is not set.如果设置不正确,它会抱怨显示未设置。 An easier check is to see if the DISPLAY variable is automatically set in the Linux server.更简单的检查是查看 Linux 服务器中是否自动设置了 DISPLAY 变量。

Hopefully everything works after these steps.希望在这些步骤之后一切正常。

If this does not work, there is another trick:如果这不起作用,还有另一个技巧:

  1. Install Xming and start a display with the display number 0 as shown up.安装 Xming 并启动一个显示编号为 0 的显示,如图所示。

  2. Install Putty安装腻子

  3. Use Putty to connect to the remote Linux system and make sure the X11 works for that Putty session, remember to check the X11 forwarding in SSH options as shown:使用 Putty 连接到远程 Linux 系统并确保 X11 适用于该 Putty session,记得检查 Z765553E6C7AC8592C389ACB9878A050 中的 X11 转发选项,如图所示:

在此处输入图像描述

  1. Echo $DISPLAY in putty, and should see the output value such as localhost:15.0在 putty 中回显 $DISPLAY,应该会看到 output 值,例如 localhost:15.0

  2. In the VSCode remote ssh, connect to the remote Linux too, if the X11 does work, then set it DISPLAY variable to be the same as putty: setenv DISPLAY localhost:15.0在 VSCode 远程 ssh 中,也连接远程 Linux,如果 X11 可以工作,则将其 DISPLAY 变量设置为与 putty 相同: setenv DISPLAY localhost:15.0

Things work like a charm事情就像一个魅力

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM