Sunday 30 September 2018

xorg - Setting up X11 forwarding over SSH on Windows 10 Subsystem for Linux?


I have a Raspberry Pi 3 Model B+ connected to my local network and I can SSH into it with no problems. This does cause some problems though as everything is done on the command line.


What I would really like to do is use X11 forwarding by using the SSH client that comes with Windows Subsystem for Linux. I am running Windows 10 Pro with the 1803 update installed.


I'm just curious about how I might go about using this feature? If it won't work in Windows 10 natively then I can always run a Linux virtual machine to connect to the Raspberry Pi.



Answer



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.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...