Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote-SSH X11 Forwarding not working #4600

Closed
plwalsh opened this issue Mar 4, 2021 · 49 comments
Closed

Remote-SSH X11 Forwarding not working #4600

plwalsh opened this issue Mar 4, 2021 · 49 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug ssh Issue in vscode-remote SSH

Comments

@plwalsh
Copy link

plwalsh commented Mar 4, 2021

  • VSCode Version: 1.54.0-insider (42e27fe5)
  • Local OS Version: Windows_NT x64 10.0.16299
  • Remote OS Version: Red Hat Enterprise Linux Workstation release 7.9 (Maipo)
  • Remote Extension/Connection Type: SSH

Steps to Reproduce:

  1. Start Xming server on local Windows 10 OS.
  2. Configure an .ssh/config file as such:
    Host test-machine
        User <username>
        HostName <hostname>
        ForwardX11 yes
    
  3. Run VSCode command "Remote-SSH: Connect to host..." and choose test-machine (remote Linux host).
  4. Wait for new VSCode window to launch and integrated terminal to open.
  5. Run a test program in the integrated terminal:
    $ glxgears
    Error: couldn't open display (null)
    
  6. Check value of DISPLAY variable:
    $ echo $DISPLAY
    
    

Output log from Remote-SSH channel:

Click to expand
[17:43:58.783] Log Level: 2
[17:43:58.793] [email protected]
[17:43:58.793] win32 x64
[17:43:58.794] SSH Resolver called for "ssh-remote+test-machine", attempt 1
[17:43:58.794] "remote.SSH.useLocalServer": false
[17:43:58.794] "remote.SSH.showLoginTerminal": false
[17:43:58.794] "remote.SSH.remotePlatform": {"test-machine":"linux"}
[17:43:58.795] "remote.SSH.sshPath": undefined
[17:43:58.795] "remote.SSH.sshConfigurationFile": undefined
[17:43:58.795] "remote.SSH.useFlock": true
[17:43:58.795] "remote.SSH.lockfilesInTmp": false
[17:43:58.795] "remote.SSH.localServerDownload": auto
[17:43:58.795] "remote.SSH.remoteServerListenOnSocket": false
[17:43:58.795] "remote.SSH.showLoginTerminal": false
[17:43:58.796] "remote.SSH.defaultExtensions": []
[17:43:58.796] SSH Resolver called for host: test-machine
[17:43:58.796] Setting up SSH remote "test-machine"
[17:43:58.815] Using commit id "42e27fe5cdc58539dad9867970326a297eb8cacf" and quality "insider" for server
[17:43:58.819] Install and start server if needed
[17:44:00.722] Checking ssh with "ssh -V"
[17:44:01.182] > OpenSSH_8.0p1, OpenSSL 1.1.1c  28 May 2019

[17:44:01.188] Running script with connection command: ssh -T -D 51498 "test-machine" bash
[17:44:01.191] Terminal shell path: C:\windows\System32\cmd.exe
[17:44:01.366] > 
[17:44:01.367] Got some output, clearing connection timeout
[17:44:02.050] > 
[17:44:02.522] > 30ab31aac300: running
> 
[17:44:02.583] > Acquiring lock on /home/<user>/.vscode-server-insiders/bin/42e27fe5cdc58539dad9
> 867970326a297eb8cacf/vscode-remote-lock.<user>.42e27fe5cdc58539dad9867970326a29
> 7eb8cacf
> Found existing installation at /home/<user>/.vscode-server-insiders/bin/42e27fe
> 5cdc58539dad9867970326a297eb8cacf...
> Checking /home/<user>/.vscode-server-insiders/.42e27fe5cdc58539dad9867970326a29
> 7eb8cacf.log and /home/<user>/.vscode-server-insiders/.42e27fe5cdc58539dad98679
> 70326a297eb8cacf.pid for a running server
> Looking for server with pid: 16023
> 
[17:44:02.607] > Found running server...
> 
> *
> * Reminder: You may only use this software with Visual Studio family products,
> * as described in the license (https://go.microsoft.com/fwlink/?linkid=2077057)
> *
> 
> Checking server status on port 39445 with wget
> 30ab31aac300: start
> SSH_AUTH_SOCK====
> DISPLAY====
> 
[17:44:02.679] > webUiAccessToken====
> listeningOn==39445==
> osReleaseId==rhel==
> arch==x86_64==
> tmpDir==/run/user/<uid>==
> platform==linux==
> unpackResult====
> didLocalDownload==0==
> downloadTime====
> installTime====
> extInstallTime====
> serverStartTime====
> connectionToken==1aaa1a11-1aaa-111a-11a1-11111a1aaa1a==
> 30ab31aac300: end
> 
[17:44:02.679] Received install output: 
SSH_AUTH_SOCK====
DISPLAY====
webUiAccessToken====
listeningOn==39445==
osReleaseId==rhel==
arch==x86_64==
tmpDir==/run/user/<uid>==
platform==linux==
unpackResult====
didLocalDownload==0==
downloadTime====
installTime====
extInstallTime====
serverStartTime====
connectionToken==1aaa1a11-1aaa-111a-11a1-11111a1aaa1a==

[17:44:02.679] Remote server is listening on 39445
[17:44:02.679] Parsed server configuration: {"serverConfiguration":{"remoteListeningOn":{"port":39445},"osReleaseId":"rhel","arch":"x86_64","webUiAccessToken":"","sshAuthSock":"","display":"","tmpDir":"/run/user/<uid>","platform":"linux","connectionToken":"1aaa1a11-1aaa-111a-11a1-11111a1aaa1a"},"installUnpackCode":""}
[17:44:02.681] Starting forwarding server. localPort 51518 -> socksPort 51498 -> remotePort 39445
[17:44:02.682] Forwarding server listening on 51518
[17:44:02.682] Waiting for ssh tunnel to be ready
[17:44:02.683] Tunneled 39445 to local port 51518
[17:44:02.683] Resolved "ssh-remote+test-machine" to "127.0.0.1:51518"
[17:44:02.684] [Forwarding server 51518] Got connection 0
[17:44:02.693] ------




[17:44:02.760] [Forwarding server 51518] Got connection 1
[17:44:02.870] [Forwarding server 51518] Got connection 2
[17:44:04.619] [Forwarding server 51518] Got connection 3

/cc @roblourens

@github-actions github-actions bot added the ssh Issue in vscode-remote SSH label Mar 5, 2021
@roblourens
Copy link
Member

This says that DISPLAY was not defined in the ssh process. What do you get if you run echo "echo $DISPLAY" | ssh test-machine?

@roblourens roblourens added the info-needed Issue requires more information from poster label Mar 5, 2021
@plwalsh
Copy link
Author

plwalsh commented Mar 5, 2021

Where/when exactly should I run that command? In my local Windows 10 shell? Or inside the integrated terminal after I'm already connected to test-machine?

Maybe I'm not understanding how the feature should work? My usual setup is to start up Xming on Windows 10, then open PuTTY, check the "Enable X11 Forwarding" checkbox, and start an ssh connection to a Linux machine. That works just fine for interacting with graphical windows launched out of the PuTTY shell.

My assumption with this new extension feature was that I would simply be able to substitute VSCode for PuTTY. So I start up Xming on Windows 10, then open VSCode to connect to my remote Linux host. And I assumed at that point I would be able to launch graphical windows from inside the integrated terminal.

Is there a step I'm missing? Do I need to be manually setting a DISPLAY variable in my Windows 10 environment before opening VSCode?

@bersbersbers
Copy link

bersbersbers commented Mar 5, 2021

My understanding (to speed things up by a few time zones :D)

Where/when exactly should I run that command? In my local Windows 10 shell?

I think yes. VS Code uses some ssh.exe in the background to connect, so this tests if your config is read correctly by ssh.exe to enable X11 forwarding. By the way, I get a -bash: line 1: echo : command not found when running this on Windows. What works instead is ssh b310-ws01 echo $DISPLAY, but this may behave a little different. (It prints nothing for me.)

You may also add -v as in ssh -v test-machine, which is when I am seeing this:

debug1: X11 forwarding requested but DISPLAY not set

ssh -v -X test-maschine also prints this line.

[Interestingly, ssh -v -x test-maschine does not print this line, but does not set $DISPLAY, either. Edit: This is because -x disables X11 forwarding, according to man ssh.]

Maybe I'm not understanding how the feature should work? My usual setup is to start up Xming on Windows 10, then open PuTTY, check the "Enable X11 Forwarding" checkbox, and start an ssh connection to a Linux machine. That works just fine for interacting with graphical windows launched out of the PuTTY shell.

My assumption with this new extension feature was that I would simply be able to substitute VSCode for PuTTY. So I start up Xming on Windows 10, then open VSCode to connect to my remote Linux host. And I assumed at that point I would be able to launch graphical windows from inside the integrated terminal.

I think your understanding is correct.

Is there a step I'm missing? Do I need to be manually setting a DISPLAY variable in my Windows 10 environment before opening VSCode?

I don't think so.

@bersbersbers
Copy link

bersbersbers commented Mar 5, 2021

I have figured out a couple of things in my testing, using OpenSSH_for_Windows_8.1p1, LibreSSL 2.9.2 and VcXsrv 1.20.8.1:

  • When testing X11 over ssh.exe in the Windows terminal, it seems that DISPLAY needs to be set locally. ssh.exe does not seem to use a sensible default when it's missing. Also, just setting it to :0 is not sufficient (compare Issues with trusted X11 forwarding and VcXsrv PowerShell/Win32-OpenSSH#1563 (comment)), I needed to set it at least to localhost:0 (and am now setting it globally to 127.0.01:0.0, see below). I would expect that this setting is not necessary when VS Code launches ssh.exe (because VS Code can take care of that), but in the Windows terminal, be sure to do set DISPLAY=localhost:0.0 before running ssh.exe. The same seems to be true for OpenSSH_8.4p1, OpenSSL 1.1.1i 8 Dec 2020 from Git for Windows.
  • I was only able to connect X11 using ssh -Y, not ssh -X. Plain ssh connects to X11 only when both ForwardX11 yes and ForwardX11Trusted yes are in my local ssh_config. This is also true for the Git one, too. Also compare Issues with trusted X11 forwarding and VcXsrv PowerShell/Win32-OpenSSH#1563 (comment).
  • The above certainly had something to do with xauth stuff: I did get debug1: No xauth program.) while xauth was available on my server (/usr/bin/xauth). So I also tried around a bit with XAuthLocation locally, and with Issues with trusted X11 forwarding and VcXsrv PowerShell/Win32-OpenSSH#1563 (comment) being extremely helpful, it is now working for me like this:
Host machine
    # set DISPLAY=127.0.0.1:0.0
    # set TMPDIR=%TEMP%
    # the following is equivalent to ssh -X
    ForwardX11 yes
    # the previous and the following to ssh -Y
    # ForwardX11Trusted yes
    XAuthLocation C:/Progra~1/VcXsrv/xauth.exe
    # LogLevel DEBUG2

which works for both OpenSSH for Windows and Git's ssh.exe.

@plwalsh
Copy link
Author

plwalsh commented Mar 5, 2021

Wow, I noticed so many of those same things yesterday while trying to get this all to work:

  • My OpenSSH does come from Git for Windows.

    • (I mostly use Git-bash when I need a terminal in Windows. Haven't learned PowerShell yet, because I do most of my work in Linux.)
  • When in Git-bash, I needed to manually export a DISPLAY variable; I believe localhost:0 is what worked.

    • Then I was only able to get X11 working by using -Y for Trusted and not -X.
  • In various configurations, I also saw the same messages being printed by ssh -v ...:

    debug1: X11 forwarding requested but DISPLAY not set

    and

    debug1: No xauth program.

  • I didn't know what to do about the xauth program, but I actually had downloaded VcXsrv and was thinking about trying that instead of Xming. (Thinking it'd magically solve all my problems.)

    • I just wasn't sure if installing it alongside Xming would cause more problems; so I decided to wait.

Thank you for your detailed responses! Just to clarify, though, you were in fact able to get X11 forwarding working inside VSCode Remote-SSH with the single addition of setting an XAuthLocation in your ssh config to .../VcXsrv/xauth.exe?

@bersbersbers
Copy link

bersbersbers commented Mar 5, 2021

Thank you for your detailed responses! Just to clarify, though, you were in fact able to get X11 forwarding working inside VSCode Remote-SSH with the single addition of setting an XAuthLocation in your ssh config to .../VcXsrv/xauth.exe?

Basically, yes. In addition, don't forget to replace localhost by 127.0.0.1 for VcXsrv. Everything else (avoiding spaces in VcXsrv's path, either during installation or by using a tilde later; and setting TMPDIR) may be specific to my OpenSSH for Windows client. Either way, when doing the above, it works for OpenSSH for Windows as well as Git's SSH client.

@bersbersbers
Copy link

(Finally, what I find notable that I did not have to do any of these gymnastics with https://marketplace.visualstudio.com/items?itemName=spadin.remote-x11.)

@plwalsh
Copy link
Author

plwalsh commented Mar 5, 2021

(Finally, what I find notable that I did not have to do any of these gymnastics with https://marketplace.visualstudio.com/items?itemName=spadin.remote-x11.)

Haha yea, I was previously using that extension, and it does work well. I disabled it, though, when I saw that X11 was now supposed to be handled natively with the latest Remote-SSH extension update. The release notes didn't mention anything about not working on Windows, but I see it was specifically tested on macOS and Linux in #4522?

@codekitchen
Copy link

I can't get this new feature to work either with plugin version 0.65.1

I have confirmed that it works fine outside of vscode. If I do a simple ssh my-host and echo $DISPLAY from terminal.app the var is set to localhost:11.0. But with vscode-remote using the same my-host config, the DISPLAY env var isn't set.

@plwalsh
Copy link
Author

plwalsh commented Mar 8, 2021

@codekitchen, what are your local and remote OSes?

@codekitchen
Copy link

Local is MacOS Big Sur 11.2.2 (using XQuartz), remote is Ubuntu 18.04.

I verified that vscode running against a local dir on my mac has DISPLAY set as expected.

@plwalsh
Copy link
Author

plwalsh commented Mar 8, 2021

Local is MacOS Big Sur 11.2.2 (using XQuartz), remote is Ubuntu 18.04.

Interesting. It looks like MacOS functionality was verified in #4522 using XQuartz without any trouble.

@codekitchen
Copy link

I'm reading through the "Remote - SSH" output and I see this:

Local server env: {"DISPLAY":"/private/tmp/com.apple.launchd.mTXu4fDsze/org.xquartz:0" ...

So it seems like at least the local vscode side knows about the DISPLAY var, it's just not making it to the remote side? I can share the full log with somebody if it's useful.

@bersbersbers
Copy link

bersbersbers commented Mar 9, 2021

@codekitchen I was seeing the same thing sporadically on Windows connecting to Linux with 0.65.1: DISPLAY was set, but I got Error: Can't open display: localhost:10.0.

What helped for me was installing 0.65.0 and reloading:
image

Interestingly, installing 0.65.1 after that still worked. But maybe it does help tracking this down.

@codekitchen
Copy link

@bersbersbers thanks but if your DISPLAY var was set, that sounds like something different -- mine isn't getting set at all.

@bersbersbers
Copy link

@bersbersbers thanks but if your DISPLAY var was set, that sounds like something different -- mine isn't getting set at all.

Yes, agreed. I must have misread your posts, sorry for that.

@devsnek
Copy link

devsnek commented Mar 13, 2021

I was able to get this to work by doing the following:

  1. mkdir \dev and echo "x" > \dev\tty (for some reason openssh for windows crashes without this)

  2. Setting the DISPLAY env in vscode settings:

        "terminal.integrated.env.windows": {
            "DISPLAY": "localhost:0.0"
        },

@bersbersbers
Copy link

@devsnek and for the record:

  1. mkdir \dev and echo "x" > \dev\tty (for some reason openssh for windows crashes without this)

See PowerShell/openssh-portable#447 (comment).

@seyeeet
Copy link

seyeeet commented Apr 23, 2021

Totally a newbie here:
can someone please summarize how to do it?
Like what should I do on my localmachine (windows) and then what to do on my remote machine (linux)?
I tried that x11 extension as well but keep getting Failed to getDISPLAY: Error: Running the contributed command: remote-x11-ssh.connect failed.
A detail instruction on how to do it will be super duper helpful.
I use the anaconda terminal in windows to ssh to the server, do i need to install putty or xming? "(

@niveshd
Copy link

niveshd commented Apr 29, 2021

Totally a newbie here:
can someone please summarize how to do it?
Like what should I do on my localmachine (windows) and then what to do on my remote machine (linux)?
I tried that x11 extension as well but keep getting Failed to getDISPLAY: Error: Running the contributed command: remote-x11-ssh.connect failed.
A detail instruction on how to do it will be super duper helpful.
I use the anaconda terminal in windows to ssh to the server, do i need to install putty or xming? "(

I am also new to this. Took some time to figure out the steps outlined above.

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.

@seyeeet
Copy link

seyeeet commented Apr 29, 2021

@niveshd thanks for your help.
I am not sure if it matters or not but I my remote machine is a cluster (meaning that I had to first ssh to the head cluster and then ssh to the node cluster).
I ran the xming and I think as you mentioned the display is on ).) (specifically in the xming log is see

winInitMultiWindowWM - pthread_mutex_lock () returned.
winInitMultiWindowWM - pthread_mutex_unlock () returned.
winInitMultiWindowWM - DISPLAY=127.0.0.1:0.0
winMultiWindowXMsgProc - pthread_mutex_lock () returned.
winMultiWindowXMsgProc - pthread_mutex_unlock () returned.
winMultiWindowXMsgProc - DISPLAY=127.0.0.1:0.0
winMultiWindowXMsgProc - XOpenDisplay () returned and successfully opened the display.
winInitMultiWindowWM - XOpenDisplay () returned and successfully opened the display.
winMultiWindowXMsgProc - another window manager is running.  Exiting.

)

on windows I add the new environment as set DISPLAY=localhost:0.0 (question: do you think set DISPLAY=localhost:0.0 is fine or I should do set DISPLAY=127.0.0.1:0.0?)

as you mentioned in 4 I also added those to the \.ssh\config in windows.

then I opened the vscode via remote ssh (so in the vscode im connecting to the node through ssh).

so in the vscode, in the log(Remote Server) is see:

[2021-04-29 10:57:26.898] [remoteagent] [info] 
*
* Visual Studio Code Server
*
* Reminder: You may only use this software with Visual Studio family products,
* as described in the license https://aka.ms/vscode-remote/license
*
[2021-04-29 10:57:26.898] [remoteagent] [info] Extension host agent started.
[2021-04-29 10:57:27.580] [remoteagent] [info] [127.0.0.1][1f8943fe][ManagementConnection] New connection established.
[2021-04-29 10:57:27.908] [remoteagent] [info] [127.0.0.1][4c738d89][ExtensionHostConnection] New connection established.
[2021-04-29 10:57:28.883] [remoteagent] [info] [127.0.0.1][4c738d89][ExtensionHostConnection] <53301> Launched Extension Host Process.

I also have a log (Extension Host) which is outputing:

[2021-04-29 10:57:47.455] [exthost] [info] ExtensionService#_doActivateExtension vscode.typescript-language-features {"startup":false,"extensionId":{"value":"vscode.typescript-language-features","_lower":"vscode.typescript-language-features"},"activationEvent":"onLanguage:jsonc"}
[2021-04-29 10:57:47.456] [exthost] [info] ExtensionService#loadCommonJSModule file:///home/seyeeet/.vscode-server/bin/3c4e3df9e89829dce27b7b5c24508306b151f30d/extensions/typescript-language-features/dist/extension
[2021-04-29 10:57:47.609] [exthost] [info] ExtensionService#_doActivateExtension ms-python.python {"startup":false,"extensionId":{"value":"ms-python.python","_lower":"ms-python.python"},"activationEvent":"onLanguage:python"}
[2021-04-29 10:57:47.610] [exthost] [info] ExtensionService#loadCommonJSModule file:///home/seyeeet/.vscode-server/extensions/ms-python.python-2021.4.765268190/out/client/extension

on the Remote-SSH I see:

> 
[13:57:26.866] Received install output: 
SSH_AUTH_SOCK====
DISPLAY====
webUiAccessToken====
listeningOn==41019==
osReleaseId==centos==
arch==x86_64==
tmpDir==/run/user/1031==
platform==linux==
unpackResult====
didLocalDownload==0==
downloadTime====
installTime====
extInstallTime====
serverStartTime==120==
connectionToken==11111a11-a1a1-1a11-aa11-11aa11aa11a1==

[13:57:26.867] Remote server is listening on 41019
[13:57:26.868] Parsed server configuration: {"serverConfiguration":{"remoteListeningOn":{"port":41019},"osReleaseId":"centos","arch":"x86_64","webUiAccessToken":"","sshAuthSock":"","display":"","tmpDir":"/run/user/1031","platform":"linux","connectionToken":"11111a11-a1a1-1a11-aa11-11aa11aa11a1"},"serverStartTime":120,"installUnpackCode":""}
[13:57:26.875] Starting forwarding server. localPort 51222 -> socksPort 51219 -> remotePort 41019
[13:57:26.878] Forwarding server listening on 51222
[13:57:26.878] Waiting for ssh tunnel to be ready
[13:57:26.881] Tunneled 41019 to local port 51222
[13:57:26.881] Resolved "ssh-remote+node1" to "127.0.0.1:51222"
[13:57:26.883] [Forwarding server 51222] Got connection 0
[13:57:26.908] ------

so I am not sure if I need to set anything on the Host (linux), should I? like should I export the Display on the linux?
how should I check if the forwarding is working?

one way that I am testing that is as follow, I basically want to see images during the debugging, so I just run the debugging and try to see if
the following code will show anything in the debug consule:

import numpy as np
import matplotlib.pyplot as plt
img =  np.random.rand(300,200)
plt.imshow(img);plt.show()

but the imshow does not show anything.
I know that that code will show the images when it is not in the debug mode though.

Thanks a lot for your help in advance! :)

update:
in my launch.json file I have:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    }
  ]
}

right now (which is for debugging).
if I add


      "env": {
        "DISPLAY": "localhost:0.0"
      },

to the launch.json as soon as I want to display something it gives this error and exit the debugging:

qt.qpa.screen: QXcbConnection: Could not connect to display localhost:0.0
Could not connect to any X display.

I dont want the display be shown in a new windows, I just want it to be shown in the debugging consule, but it seems like to be so hard. or I dont know how to do it :(

@niveshd
Copy link

niveshd commented Apr 29, 2021

@seyeeet I am also using it with a cluster. On the cluster side, you don't need to set any DISPLAY. For me, once I connect, VSCode assigns a DISPLAY port on the cluster. You only need to set it on the windows side. I just set it to localhost:0.0 I don't think you need to expand the localhost.

In the config file, can you add LogLevel DEBUG2. That shows you more information in the output. Or, check in the integrated terminal, if you see the value of DISPLAY (echo $DISPLAY). Check if the integrated terminal works by using xeyes or someother x11 app. If that works, but not your debug launches, use the DISPLAY value from the terminal in the launch.json. I see that you have used localhost:0.0 there but that seems to be only on the windows side!!

@seyeeet
Copy link

seyeeet commented Apr 29, 2021

@niveshd Thanks for your help, but it is not still working, echo $DISPLAY in the terminal of vscode shows nothing. I did try to set it manually, but I still cannot make it work :(

did you set the localhost in the congi file?
like here:

Host node1
  # set DISPLAY=127.0.01:0.0
  # set TMPDIR=%TEMP%
  HostName node1.cm.cluster
  ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -q -X -W %h:%p [email protected]
  User Seyeeet
  IdentityFile C:\Users\Seyeeet\.ssh\authorized_keys
  ForwardAgent yes
  ForwardX11 yes
  ForwardX11Trusted yes
  LogLevel DEBUG2

@joelspadin-garmin
Copy link

I haven't yet been able to get this to work with a Windows local machine and Linux remote machine. A DISPLAY variable is being set on the remote, but when I run a program I get

Error: Can't open display: localhost:14.0

and "Remote - SSH" logs this:

debug1: client_input_channel_open: ctype x11 rchan 5 win 65536 max 16384
debug1: client_request_x11: request from ::1 44184
connect /tmp/.X11-unix/X0: No such file or directory
debug1: failure x11

If I ssh into the Linux machine from a regular terminal, forwarding works correctly.

My setup:

  • Local machine: Windows 10 build 18363
    • XcXsrv version 1.20.9.0 set to display 0
    • DISPLAY=127.0.0.1:0.0
  • Remote machine: Ubuntu 20.04.2

SSH config:

Host <hostname>
  HostName <hostname>
  User <username>
  ForwardAgent yes
  ForwardX11 yes
  ForwardX11Trusted yes
  LogLevel DEBUG2

I also see this in the logs. This pretty closely matches what it logs when I connect using ssh from a regular terminal, so it seems like it's setting things up correctly. The only difference I see between them is the channel number.

debug1: Remote: /home/username/.ssh/authorized_keys:1: key options: agent-forwardi
ng port-forwarding pty user-rc x11-forwarding
debug2: channel_input_open_confirmation: channel 2: callback start
debug1: No xauth program.
Warning: No xauth data; using fake authentication data for X11 forwarding.
debug1: Requesting X11 forwarding with authentication spoofing.
debug2: channel 2: request x11-req confirm 1
debug1: ssh_get_authentication_socket: No such file or directory
debug2: fd 3 setting TCP_NODELAY
debug2: client_session2_setup: id 2
debug1: Sending command: bash
debug2: channel 2: request exec confirm 1
debug2: channel_input_open_confirmation: channel 2: callback done
debug2: channel 2: open confirm rwindow 0 rmax 32768

debug2: channel_input_status_confirm: type 99 id 2
debug2: X11 forwarding request accepted on channel 2
debug2: channel 2: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 2

@binus
Copy link

binus commented Sep 25, 2021

Succeeded with Remote - SSH v0.65.8, windows 19043.
Information for reference:

ssh config: (key baed auth)
    ForwardX11 yes
    ForwardX11Trusted yes
Windows env: (edit in powershell, or so on)
    DISPLAY=localhost:0.0
Windows installed VcXsrv 1.20.6.0
log of remote ssh: (LogLevel DEBUG2, hide non-relavent )
(...)
[18:20:11.951] > debug1: client_input_global_request: rtype [email protected] want_reply 0
> debug2: channel_input_open_confirmation: channel 2: callback start
> debug1: No xauth program.
> Warning: No xauth data; using fake authentication data for X11 forwarding.      
> debug1: Requesting X11 forwarding with authentication spoofing.
> debug2: channel 2: request x11-req confirm 1
> debug2: fd 3 setting TCP_NODELAY
> debug2: client_session2_setup: id 2
> debug1: Sending command: bash
> debug2: channel 2: request exec confirm 1
> debug2: channel_input_open_confirmation: channel 2: callback done
> debug2: channel 2: open confirm rwindow 0 rmax 32768
> debug2: channel_input_status_confirm: type 99 id 2
> debug2: X11 forwarding request accepted on channel 2
> debug2: channel 2: rcvd adjust 2097152
> debug2: channel_input_status_confirm: type 99 id 2
> debug2: exec request accepted on channel 2
> debug2: channel 2: read<=0 rfd 6 len 0
> debug2: channel 2: read failed
> debug2: channel 2: chan_shutdown_read (i0 o0 sock -1 wfd 6 efd 8 [write])       
> debug2: channel 2: input open -> drain
> debug2: channel 2: ibuf empty
> debug2: channel 2: send eof
> debug2: channel 2: input drain -> closed
(...)
[18:20:12.135] > 3d5606dfa67d: start
> SSH_AUTH_SOCK====
> DISPLAY==localhost:21.0==
> webUiAccessToken====
(...)
[18:20:20.390] > debug1: client_input_channel_open: ctype x11 rchan 4 win 65536 max 16384
> debug1: client_request_x11: request from 127.0.0.1 55810
> debug2: fd 10 setting TCP_NODELAY
> debug2: fd 10 setting O_NONBLOCK
> debug1: channel 5: new [x11]
> debug1: confirm x11
[18:20:20.391] > 
[18:20:21.762] > debug2: channel 5: rcvd eof
> debug2: channel 5: output open -> drain
> debug2: channel 5: obuf empty
> debug2: channel 5: chan_shutdown_write (i0 o1 sock 10 wfd 10 efd -1 [closed])   
> debug2: channel 5: output drain -> closed
> debug1: channel 5: FORCE input drain
> debug2: channel 5: ibuf empty
> debug2: channel 5: send eof
> debug2: channel 5: input drain -> closed
> debug2: channel 5: send close
[18:20:21.770] > 
> debug2: channel 5: rcvd close
> debug2: channel 5: is dead
> debug2: channel 5: garbage collecting
> debug1: channel 5: free: x11, nchannels 6
(...)

@seyeeet
Copy link

seyeeet commented Oct 15, 2021

yes, I still face that issue with version 1.61.1

@roblourens roblourens added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Oct 15, 2021
@roblourens
Copy link
Member

I don't really understand what the issue is on windows, or what else Remote-SSH needs to do, but #4600 (comment) seems like useful info.

@roblourens roblourens self-assigned this Oct 15, 2021
@bdytx5
Copy link

bdytx5 commented Nov 18, 2021

would recommend the mpld3 pip package for anyone using python.. More reliable than X11 imo

@seyeeet
Copy link

seyeeet commented Nov 18, 2021

@bdytx5 interesting!!! it looks promising, but it is just very slow for images, for simple toy examples it works though!!!
any suggestion on how to do it for images, so it does not take for ever to open?

@zzeitt
Copy link

zzeitt commented Jan 20, 2022

Succeeded with Remote - SSH v0.65.8, windows 19043. Information for reference:

ssh config: (key baed auth)
    ForwardX11 yes
    ForwardX11Trusted yes
Windows env: (edit in powershell, or so on)
    DISPLAY=localhost:0.0
Windows installed VcXsrv 1.20.6.0

Hi @binus, could you give more detail about how to make it work?

I followed your configuration but still can't get this work.

  • ssh config
  • Windows env (already modified windows system variable)
  • VcXsrv installed (don't know how to let VcXsrv run in background)

Currently, I succeded by keeping MobaXterm opened as Moba will start a xserver in background.

@zzeitt
Copy link

zzeitt commented Jan 24, 2022

Finally I did it.

I wrote a tutorial post here: English ver/Chinese ver.

The key steps can be summarized as:

  1. Install VcXsrv.
  2. Configure the config file under C:\Users\[user]\.ssh\.
  3. Get the $DISPLAY value.
  4. Start up VcXsrv (Xlaunch).
  5. Set Display number & tick Disable access control.
  6. Connect to the server in VS Code.

@elasticdotventures
Copy link

It's worth mentioning the VcXsrv is not explicitly necessary for people who have Windows 11 & WSL-g (the native windows wsl-g is much faster than VcXsrv)

@zzeitt
Copy link

zzeitt commented Jun 1, 2022

It's worth mentioning the VcXsrv is not explicitly necessary for people who have Windows 11 & WSL-g (the native windows wsl-g is much faster than VcXsrv)

Didn't try it, but I found a feature request here: Remote-SSH utilizing wslg for X11 forwarding, saying this feature will not be put into backlog until it gets 10 upvotes. (One of the three votes is mine...😂)

@elasticdotventures
Copy link

elasticdotventures commented Jun 1, 2022

It's worth mentioning the VcXsrv is not explicitly necessary for people who have Windows 11 & WSL-g (the native windows wsl-g is much faster than VcXsrv)

Didn't try it, but I found a feature request here: Remote-SSH utilizing wslg for X11 forwarding, saying this feature will not be put into backlog until it gets 10 upvotes. (One of the three votes is mine...😂)

@zzeitt - I've added an upvote in solidarity. ✊

the DISPLAY variable isn't auto-setup for me (I need to set it up by hand when in a vscode window)

#267 references #589 which references #16
but the most promising is #4522
which claims to have taken code from joelspadin/vscode-remote-x11#44

For anybody running across this, if we don't get this ticket across the line in upvotes, there is a quick and easy work-around using windows terminal (not in vscode), but wslg X11 with DISPLAY works when ssh is run via wsl.exe

wsl.exe -- ssh -a -X -Y $replaceWithHostOrIP

👆 use the command in windows-terminal

(via windows terminal) in your remote host echo $DISPLAY

then in vscode window export DISPLAY=...
(replace ... with whatever the echo showed on your remote host) and everything should work properly. )

@elasticdotventures
Copy link

elasticdotventures commented Jun 1, 2022

@tanhakabir & @roblourens - i'm going to ping you on vscode dev slack, created a channel for vscode-remote-ssh happy to help debug a bit.

The issue is actually here:
Terminal shell path: C:\WINDOWS\System32\cmd.exe

even more bizzare, I've updated settings.json

"terminal.external.windowsExec": "C:\\WINDOWS\\System32\\wsl.exe"

But it doesn't change the plugin (as you'd expect), rather I see the exact same string Terminal shell path: in the vscode-python module

https://github.com/microsoft/vscode-python/blob/9f95296ebec353e2a7786c3ff42ad151e8fd409b/src/client/common/terminal/shellDetectors/vscEnvironmentShellDetector.ts#L24-L36

🤓 at this point, lemme explain what is happening. I definitely figured out why this isn't working, the plugin is running under "cmd.exe", and when C:\Windows\System32\OpenSSH\ssh.exe -a -Y -X -F "C:\Users\xxx\.ssh\config"
then the X11 settings are ignored, i.e. on the remote host echo $DISPLAY is not set

HOWEVER the exact same command, with the same config, with or without the -X -Y -a (literally it only requires the -F with ForwardX11 yes running under wsl.exe then works perfectly every single time) .. and that is why IF you try to run the ssh in (for example Windows Terminal) using cmd.exe it won't work, but under wsl it does!!!

so I think if I can figure out how to change cmd.exe to wsl.exe in the line below then this will work.

[00:23:05.271] Running script with connection command: ssh -T -D 54353 -F "C:\Users\gru3h/.ssh/config" "192.168.0.42" bash
[00:23:05.275] Terminal shell path: C:\WINDOWS\System32\cmd.exe

I've tried all of these settings.json with no luck, I can't get to the source code for remote-ssh plugin so I can't see where this actually getting the "cmd.exe" path from.

"terminal.external.windowsExec": "C:\\WINDOWS\\System32\\wsl.exe",
 terminal.integrated.shellIntegration.enabled
    "terminal.integrated.automationProfile.windows": "Ubuntu-22.04 (WSL)",
    "terminal.integrated.automationShell.windows": "wsl.exe",
    "terminal.integrated.defaultProfile.windows": "Ubuntu-22.04 (WSL)", 

🙏 i'm not even kidding when i say this has stolen a week of my life.

yep, it still occurs with the latest pre-release plugin version v0.81.2202052415

✊ The issue is that X11 forwarding isn't possible under cmd.exe
since vscode remote-ssh plugin source isn't public, i can't actually verify this.

I'm running on windows 11, insiders edition (fully patched), running vscode it is not possible to get ssh remote extension to pass the -X parameter (which will set the DISPLAY parameter)

I know vscode is reading my ~/.ssh/config file (because if I change the path, the remote hosts disappear, I have no hosts! so I'm sure it's reading the proper config file)

and I know my config file works, because I can use the same .ssh/config file directly from within wsl and it works great with or without the -X .. (using the same command) .. i.e. the -X shouldn't be required provided the .ssh/config file has ForwardX11 yes)

Debug log provided for complete reference.

[22:56:55.238] Log Level: 2
[22:56:55.239] [email protected]
[22:56:55.239] win32 x64
[22:56:55.243] SSH Resolver called for "ssh-remote+192.168.0.42", attempt 1
[22:56:55.244] "remote.SSH.useLocalServer": false
[22:56:55.244] "remote.SSH.showLoginTerminal": true
[22:56:55.244] "remote.SSH.remotePlatform": {"192.168.0.42":"linux"}
[22:56:55.244] "remote.SSH.path": undefined
[22:56:55.244] "remote.SSH.configFile": ~/.ssh/config
[22:56:55.245] "remote.SSH.useFlock": true
[22:56:55.245] "remote.SSH.lockfilesInTmp": true
[22:56:55.245] "remote.SSH.localServerDownload": auto
[22:56:55.245] "remote.SSH.remoteServerListenOnSocket": false
[22:56:55.245] "remote.SSH.showLoginTerminal": true
[22:56:55.246] "remote.SSH.defaultExtensions": []
[22:56:55.246] "remote.SSH.loglevel": 2
[22:56:55.246] "remote.SSH.enableDynamicForwarding": true
[22:56:55.247] "remote.SSH.enableRemoteCommand": false
[22:56:55.247] "remote.SSH.serverPickPortsFromRange": {}
[22:56:55.247] "remote.SSH.serverInstallPath": {}
[22:56:55.270] SSH Resolver called for host: 192.168.0.42
[22:56:55.270] Setting up SSH remote "192.168.0.42"
[22:56:55.299] Using commit id "c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5" and quality "stable" for server
[22:56:55.305] Install and start server if needed
[22:56:55.310] Checking ssh with "ssh -V"
[22:56:55.355] > OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3

[22:56:55.361] Using SSH config file "C:\Users\gru3h/.ssh/config"
[22:56:55.361] Running script with connection command: ssh -T -D 63758 -F "C:\Users\gru3h/.ssh/config" "192.168.0.42" bash
[22:56:55.365] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[22:56:56.249] > 31d21780ddf6: running
> Acquiring lock on /run/user/1000/vscode-remote-lock.brianh.c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
> �]0;C:\WINDOWS\System32\cmd.exe�
[22:56:56.250] Got some output, clearing connection timeout
[22:56:56.260] > 31d21780ddf6: running
> Acquiring lock on /run/user/1000/vscode-remote-lock.brianh.c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5  
> Found existing installation at /home/brianh/.vscode-server/bin/c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5...
> Checking /home/brianh/.vscode-server/.c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5.log and /home/brianh/.vscode-server/.c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5.pid for a running server
> Looking for server with pid: 27642
> 
> 
> 
> 
> 
> 
> Found running server...
>  
> *
> * Reminder: You may only use this software with Visual Studio family products,
> * as described in the license (https://go.microsoft.com/fwlink/?linkid=2077057)
> *
>  
[22:56:56.265] > 
> Checking server status on port 40099 with wget
> 31d21780ddf6: start
> SSH_AUTH_SOCK==/tmp/ssh-DSPJNOhV9e/agent.49919==
> DISPLAY====

@elasticdotventures
Copy link

elasticdotventures commented Jun 1, 2022

so I managed to find this link - https://zitseng.com/archives/20325 and used those instructions to set this:

   "remote.SSH.path": "C:\\users\\gru3h\\.local\\ssh.bat",

new abridged output (still trying to run cmd.exe, now command still fails, trying to run inside wsl.exe because it can't find the file C:\users\gru3h/.ssh/config in WSL. (of course!) 😔

next, i switched the ~/.ssh/config path variable in vscode to a valid WSL path /mnt/c/users/gru3h/.ssh/config
then restarted vscode

and suddenly HURRAH! i'm seeing DISPLAY===localhost:10.0 🥳
(and things aren't working great btw, i can't open new terminal windows, and there's quite a bit that doesn't work, but the DISPLAY==== variable is set!)

😖 HOWEVER, once I stop using that session remote-ssh using a File | Close Remote Connection
AND then to access a new host from vs-code running under windows 11, that path /mnt/c/Users/Gru3h/.ssh/config is now wrong and I can't see any hosts. 😭

maybe i'll be able to modify the ssh.bat or something smarter tomorrow .. but at least this proves what the issue is.

@tanhakabir
Copy link

tanhakabir commented Jun 1, 2022

@elasticdotventures thanks for the deep exploration! I'll see if I can add an experimental setting for you that let's you change the windows executable path to wsl instead of cmd.

One thing to add though is that it seems your X11 server is running only in WSL based on #4600 (comment) so it does make sense cmd doesn't work with your set up

@elasticdotventures
Copy link

elasticdotventures commented Jun 1, 2022

@tanhakabir thanks 🥰

fwiw, it probably won't be that straightforward. 🙄

as I explained the path to the ~/.ssh/config file will also need to be addressed, since vscode is starting in windows host, the remote-ssh plugin [correctly] uses windows paths. i.e.

C:\users\myuser/.ssh/config 

☝️ vscode remote-ssh plugin -- I normally would use the "remote.SSH.configFile" setting of ~/.ssh/config - this is parsed + used by the Remote-SSH plugin both as the -F filename passed to SSH, but also to load which hosts will be displayed as available for "Remote-SSH: Connect to Host" .. so if the path is a valid WSL unix path, it won't work. But someplace inside vscode or remote-ssh plugin it also expands the "~" path to C:\Users\myuser/.ssh/config

🤓 notice the combination of back \ and forward / slashes above. 🙈🙉🙊 the fun is just starting.

🫣 of course, by switching to the .bat example as suggested by the zitseng.com/archives/20325 [hereafter: "zitseng method"], I was able to execute WSL, but found inside of WSL, the windows path to C:\users\myuser/.ssh/config is nonsensical & invalid [when running in WSL]

I hacked my way around this (as a test) by using "the zitseng method" and setting my settings.json for an experiment as such:

"remote.SSH.configFile": "/mnt/c/Users/myuser/.ssh/config",
"remote.SSH.path": "C:\\Users\\myuser\\.local\\ssh.bat",

in the vscode settings, now I can close+re-open VSCODE .. and the most recent session auto-restart with the proper settings and almost semi-work ... 🤓at least the DISPLAY====localhost:10.0 appears in the initialization which has never happened (for me) under cmd.exe 🥳

HOWEVER - this approach breaks the remote-ssh plugin from being able to select a new host in vscode (i.e. F1 + Remote-SSH: Connect to Host ...) is now broken because the remote.SSH.configFile path to SSH config now INVALID in windows cmd.exe: 🤦‍♂️

"remote.SSH.configFile": "/mnt/c/Users/myuser/.ssh/config",

@elasticdotventures
Copy link

elasticdotventures commented Jun 1, 2022

@tanhakabir so my proposal (after sleeping on this)

I think the Remote-SSH plugin should probably load/select the shell from a standard 'defacto' vscode place such as:

"terminal.integrated.profiles.windows": {
}

the .bat file wouldn't be necessary if I could tell it to use wsl.exe as the shell,

AND ADDITIONALLY:

some mechanism such as a boolean to disable the windows path expansion to prevent

"remote.SSH.configFile": "~/.ssh/config",

from becoming C:\Users\myuser/.sss/config

@tanhakabir
Copy link

@elasticdotventures I realized we have a longstanding issue to get WSL SSH working: #937 so your request would fall under that request. I'll aim to have some time this upcoming month to explore this but until then I would follow #937 instead

@bdytx5
Copy link

bdytx5 commented Jun 3, 2022

@seyeeet checkout imgcat with iterm. Works well for viewing images!

@bdytx5
Copy link

bdytx5 commented Jun 3, 2022

@tanhakabir unrelated but a better way to debug programs with command line arguments would be a huge improvement! Problem is that you have to make this launch.json file in a very specific format. This is very tedious when using lots of arguments. You should just be able to debug directly from the command line instead of having to use a launch.json file.

@tanhakabir
Copy link

@bdytx5 thanks for the suggestion! Would you be able to file an issue on the vscode repo reiterating this feedback?

@fastyangmh

This comment was marked as spam.

@Sandy4321
Copy link

still it is not clear
is it possible to get plots when debugging remotely from windows for AWS Unix based code?
meaning use VS code on windows, but running actual python code on Linux and get full debugging capability , like to see plots from matplotlib

@tanhakabir
Copy link

@Sandy4321 that should be possible today since you have access to all the compute of your remote environment and can open Jupyter notebooks or Python files on the remote.

@tanhakabir
Copy link

Closing this issue due to inactivity though.

@Kenny2github
Copy link

Just noting that I needed to create a PEM version of my SSH private key:

copy id_rsa id_rsa.pem
rem you will be prompted to set your passphrase again
ssh-keygen -p -m PEM -f id_rsa.pem

And then point Remote-X11 to it:
Remote-X11 private key setting
(Set this to the path to the PEM file.)

@github-actions github-actions bot locked and limited conversation to collaborators Oct 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug ssh Issue in vscode-remote SSH
Projects
None yet
Development

No branches or pull requests