Score:0

X11 forwarding through WSL

gl flag

I would like to connect to a remove linux machine via ssh from my windows machine, and forward the x11 server from that machine to mine to be able to view small interactive windows like those generated by matplotlib (with the qt backend). Since the WSL2 already somehow forwards x11, I guessed that I don't need to install anything else to my windows box and I could just proxy through the existing WSL installation with x11 forwarding. I enter wsl2 ubuntu by running the command (on the windows powershell with openssh installed):

ssh -X <wsl-user>@localhost -p 2222

(I have configured the ssh server running in the wsl instance to use port 2222) Then I execute this:

ssh -X <remote-user>@<remote-host> And it works! (I can view a gui xclock)

Since I want to connect to <remote-host> with the vscode Remote-Host extension I would like to be able to configure the remote host to do all this intermediate stuff automatically. My ssh config looks like this:

Host remote-host
  HostName <remote-host>
  User <remote-user>
  ForwardX11 yes
  ProxyJump wsl

Host wsl
  HostName localhost
  User <wsl-user>
  Port 2222
  ForwardX11 yes

Now when I run ssh remote-host, it should be equivalent to the previous process. Well, it looks like that isn't true. When I run xclock on the remote machine I get the output:

connect 127.0.0.1 port 6000: Connection refused
Error: Can't open display: <remote-hostname>:12.0

I have tried the proxycommand option, which I think is general enough to do exactly what I want, but it is not working either (probably because I don't understand it well enough). Changing the X11UseLocalhost option in the wsl and remote machine config did not help either.

I don't understand how ProxyJump (and the X11Forwarding options) is not all I need to do for this to work.

(I have also fumbled around with the X11ForwardingTrusted options because of a message that shows up after connected with the configured host: Warning: No xauth data; using fake authentication data for X11 forwarding., but this warning shows up with the working method as well)

UPDATE: I connected to my machine with the working method and with the problematic method and it seems that the DISPLAY environmental variable is set incorrectly in the proxyjump method; reexporting the variable to match the working method works. However, this is a sad patch and I believe there is a better way than having 2 connections open.

UPDATE 2: It looks like I was complicating things much more than I had to. WSL2 doesn't seem to use X11 forwarding to display in windows. By proxyjumping through WSL to the remote system, I actually forward my windows display to the remote, not my WSLdisplay. Since my windows display does not have an X11 client, it failed. I can simply ssh from the built in windows client without X11 forwarding, and sshfrom the WSLssh client WITH X11 forwarding, and use the DISPLAY variable created by the WSL-remote session in the windows-remote session. This still leaves me with 2 sessions but at the very least I am not pointlessly proxyjumping around. I attempted using the WSL ssh client directly by using the command wsl ssh ... but vscode Remote-SSH did not like using wsl ssh instead of the built in windows ssh. This takes us to the topic of using WSL ssh in vscode, which is not the original question's focus, so I will leave it at that.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.