TIL - X11 forwarding in WSLg

Apropos nothing, I was struggling with forwarding an X11 Linux application (, if you must know) to my Windows 11 22H2 desktop, which includes WSLg, the baked in display and audio server, and wasn’t getting anywhere because:

  • runs inside a Hyper-V environment, so you are effectively behind outbound NAT.
  • Every single piece of wisdom on the Internet about this focuses on installing third-party X server software (which I don’t want to do).
  • Fedora, for some reason, breaks ssh -X, xauth and setting DISPLAY manually (I still haven’t figured out why).

What worked

In a nutshell, I had to use an Ubuntu machine, and just doing ssh -X [email protected] worked fine. I will update this post when I figure out why it failed on Fedora.

But there is a technique I’m intrigued about, and that I was trying on the Fedora machine before trying another one: forwarding the remote X11 TCP socket to the local domain socket, something I had forgotten was possible, and which really should have worked:

# OpenSCAD complains bitterly without this
ssh -R 6020:/tmp/.X11-unix/X0 [email protected]
# on the remote machine
export DISPLAY=:20
# run your app

Again this should have worked in Fedora (which was complaining about auth errors with plain ssh -X or -Y), but didn’t. However, it worked first time on Ubuntu, and is a nice technique to have on hand if, for some reason, xauth fails and you don’t want to mess about with such arcane things as MIT-MAGIC-COOKIE-1.

And then I decided to try ssh -X again and lo, it worked on Ubuntu but not in Fedora. Personally, I suspect GNOME, or the tricks modern session managers use to coexist with Wayland. Sigh.

Still, it’s nice to know the WSLg team went to so much trouble to make X11 work seamlessly on the Windows side.

Next I needed to get X11 apps to render in HIDPI without looking like they were designed for ants.

Forcing Scaling

Setting these on the remote machine worked for me on my :

# for Qt apps like OpenSCAD
export QT_SCALE_FACTOR=1.3
export QT_FONT_DPI=96
# GTK, because I also needed the STL viewer to work
export GDK_SCALE=2
export GDK_DPI_SCALE=0.5
# gsettings set org.gnome.desktop.interface text-scaling-factor 2.0 # use sparingly, because it's persistent.

Also, microsoft-edge on Linux honors --force-device-scale-factor, so I could also use 1.3 to get a decent experience.