10

I use Windows VS code and this extensions "Remote SSH", "Remote X11", "Remote X11 (SSH)" to connect and to get graphics from remote server.

I run VcXsrv, Pageant. X11 forwarding works if I connect with Pageant directly. It even works in VS code terminal if I set "export DISPLAY=localhost:10.0" in remote server. So all works besides Remote X11, it cant set DISPLAY variable, with this log: Failed to get DISPLAY: Error: Invalid cygwin unix socket path

razrabochka
  • 103
  • 1
  • 1
  • 5

3 Answers3

9

I found the solution to this here 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).

Steps to connect from Windows to Linux:

  1. Install Xming (Should also work with VcXsrv). Start Xming (Default Display:0.0)
  2. Install Remote-SSH. You don't need the other extensions. Nor do you need a running terminal with active x11 connection.
  3. Add a new environment variable to Windows: DISPLAY = localhost:0.0 (Adjust this according to your Xming setting. I prefer the default value).
  4. Connect remotely using 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. 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.

Hopefully everything works after these steps.

nivesh
  • 109
  • 1
  • 6
  • This is great on Linux, now I have to figure out how to translate for Windows users. – Bday Feb 08 '22 at 19:47
  • 2
    I see that this is supposed to be for Windows. More info on 3 would be good. How do you set the display in Windows so that SSH makes use of it? – Bday Feb 08 '22 at 20:59
  • agree with Bday – Julio Spinelli Apr 15 '22 at 13:59
  • 2
    Here is a tutorial on how to do it: https://zhuanlan.zhihu.com/p/461378596 – Julio Spinelli Apr 15 '22 at 14:26
  • Note: Prerequisite, The server terminal must be able to ping through to the local IP! – xing cui Dec 06 '22 at 06:46
  • Followed your steps, and to piggy back off of Bday's comment, I added a DISPLAY environment variable with the value of `localhost:0.0`. At this site I was able to Create a User Environment Variable in Windows 10: https://archive.is/sfhK7#selection-533.3-533.51 – kyrlon Jan 27 '23 at 20:14
2

Reproduced from zhuanlan.zhihu.com see comment above. Basically, all we need to know is that on the server side (mostly are Linux OSs), they use X11 protocol to display GUI.

IMHO, the X11 protocol is consists of two parts, the XServer and the XClient. XServer is the one who actually draws the pixels on display equipment, while the XClient takes charge of processing the logics behind displaying.

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.

Step 1: VS Code Configuration

Step 1.1: Install VS Code

Step 1.2: Install Remote-SSH plugin

enter image description here

Step 2: Client Machine Configuration (Windows)

Step 2.1: Modify config file

The config file is used by SSH. It locates at C:\Users\[user]\.ssh\config, where [user] should be your username.

To establish a key-based SSH connection, you should specify the path of the key file. What's more, to enable X11 Forwarding, the following two lines should be added to config file:

ForwardX11 yes
ForwardX11Trusted yes

enter image description here example of config file

Step 2.2: Download & install VcXsrv

Download VcXsrv from here: VcXsrv Windows X Server download | SourceForge.net

After the installation, the following software should appear in your Menus. This is exactly the XServer we need.

enter image description here

Step 3: 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.

Step 3.1: Get $DISPLAY

Usually, the $DISPLAY variable is set by default. So, type the following command in your server's terminal, and it will output something in the form of IP:D.S. Remember the D's value, which is 10 here.

> echo $DISPLAY
localhost:10.0

If the output is blank, you should set the $DISPLAY value by yourself.

export DISPLAY=localhost:10.0 

Step 4: 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. enter image description here

Tick Disable access control

enter image description here

There should be an 'X' icon on your task bar when you run the software successfully.

enter image description here

Step 4.2: Run VS Code & connect to the server

Check the value of $DISPLAY, it should be consistent with your before setting.

Then type the command:

xeyes

If the GUI of two eyes shows up, it means you make it!

enter image description here

Step 4.3: Test your own GUI program (optional)

You can even run your self-written GUI, pretty cool huh?

enter image description here

Dave Mackey
  • 4,306
  • 21
  • 78
  • 136
Julio Spinelli
  • 587
  • 3
  • 16
  • I have seriously tried all your steps and they still don't work, can you answer the questions I gave below? https://unix.stackexchange.com/questions/750145/x-server-hang-for-a-couple-minites-and-cant-open-display-errors – xing cui Jun 29 '23 at 07:08
2

If this does not work, there is another trick:

  1. Install Xming and start a display with the display number 0 as shown up.

  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:

enter image description here

  1. Echo $DISPLAY in putty, and should see the output value such as 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

Things work like a charm

Chunde Huang
  • 337
  • 3
  • 9