Setting up X11 forwarding over SSH on Windows 10 Subsystem for Linux?
On the WSL shell, make sure you have exported the fully qualified DISPLAY
export DISPLAY=localhost:0.0
The following does not work:
export DISPLAY=:0.0
:0.0 relies on a UNIX domain socket (instead of a TCP/IP socket) and somehow the X-forwarding doesn't get hooked up correctly. I had the same problem.
update: wsl2 is almost the same, but when using VcXsrv, you must check the disable access control
box.
This is definitely possible given your current setup. Note that you also have the option of using Putty but either way, you'll need to have an X server running on the client machine, your Windows Subsystem for Linux — WSL. The client-server model of the X window system is partially what makes X forwarding so easy to pull off. All you need is an X server running on host and client.
Raspberry Pi (Host) Configuration
First, you'll want to make a minor config adjustment to your SSH server on the host machine (your Raspberry Pi). First, find your sshd_config file within the etc directory. You can run these commands by ssh-ing into the Raspberry Pi (with a sudo-capable account), or accessing the Pi directly and then opening a terminal.
Once you're in, run the command:
cd /etc/ssh
Make a backup of your sshd config file:
cp sshd_config sshd_config.ORIG
Now open the original file in a text editor with:
sudo nano sshd_config
You can choose any text editor you're comfortable with (see here for the nano text editor shortcuts). This is the main config file for the ssh server. Find and uncomment the following lines:
X11Forwarding yes
X11UseForwarding yes
Save and exit. Now you'll need to restart your Pi's SSH server with:
sudo systemctl restart sshd
Windows (Client) Setup
You're done with your host. Now all you need to do is install an X server for Windows. There are a few options to choose from but I would go with Cygwin X which you can download here. Install it and once you run it, it should spawn a little window on your client which will be used to display the X program. You can now test that X forwarding is happening by returning to your WSL shell and running the simple command:
xclock
A simple clock should appear in the window spawned by Cygwin. You can terminate the clock by returning to your WSL shell and hitting Ctrl+C. If this command isn't recognized, you may first need to install x11-graphics applications on the host machine with:
sudo apt-get install x11-apps
X forwarding should now be enabled for you and you can now run most if not all of your Raspberry Pi's applications from Windows.
Note on XDMCP, FreeNX
You may wish to take things a step further and set things up to run an entire desktop environment from your Pi rather than just app-by-app which is what X forwarding allows. Here are a couple common options available to you:
- XDMCP: This is the easiest to set up but is notoriously insecure and most authorities only recommend you ever run it on a trusted, wired LAN (like your home network). This may be more trouble than it's worth but if you're curious to look into it, see this Rasp Pi thread for the initial setup.
- FreeNX: More secure than XDMCP and probably worth the time to set up if you'll want to do this regularly and possibly from another network entirely. You'll need to install a FreeNX server on the host, then use another piece of software - NoMachine - on your Windows client. See here for a very detailed guide.
X11 considers the machine that DISPLAYS the graphical interface to be the X Windows SERVER, and the machine that provides the information to be displayed as the X Windows CLIENT. This is the reverse of the usual client/server relationship. Think of the local machine (the one with the physical display) as the graphics server and the remote machine as the graphics client.