Enabling X11 forwarding on the Raspberry Pi will allow you to run graphical applications on the device from your remote PC. This has some advantages over using xrdp or VNC on your Raspberry Pi, since the applications will look better since they are running on your local PC. In this tutorial, you will see how to enable X11 forwarding on a Raspberry Pi.
In this tutorial you will learn:
- How to enable X11 forwarding on the Raspberry Pi
- How to run an X program from the client in an X11 forwarding session
|Category||Requirements, Conventions or Software Version Used|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to enable X11 forwarding on Raspberry Pi step by step instructions
Follow along with the steps below to install enable X11 forwarding on your Raspberry Pi. Then, we will show how to use a client machine to utilize the X11 forwarding on the Raspberry Pi (server) to display graphical applications.
X11window system has a client-server architecture: the clients are the many graphical applications requesting connection to the server which manages displays. The X11 server and its clients often run on the same machine, but this it’s not necessary. It’s possible to access a remote X11 server via a dedicated but unsecure protocol.
Opensshlet us run the connection securely, creating an encrypted tunnel. The option that controls this behavior is
X11Forwarding. The feature is generally disabled by default, so it is set to
- In case it is not already installed, install the OpenSSH Server package on your Raspberry Pi:
$ sudo apt update $ sudo apt install openssh-server
- Using the terminal on your Raspberry Pi, open the
sshdconfiguration file with nano or your preferred text editor. You will need to use root permissions (
sudo) for this:
$ sudo nano /etc/ssh/sshd_config
- In this file, scroll down until you find the following line, and then uncomment it by removing the
#symbol in front of it.
Save your changes and exit the file when finished uncommenting the line.
- For the changes to take effect, restart the SSH service on the Raspberry Pi:
$ sudo systemctl restart ssh
That is all the configuration we will need to do on the Raspberry Pi. All SSH users should now be able to utilize X11 forwarding from a remote system.
- From the remote system, use the following syntax with the
-Xoption to take advantage of the X11 forwarding. For example, to use the SSH connection to launch the “mousepad” application (a lightweight text editor) and control it using X11 Forwarding, we run:
$ ssh linuxconfig@raspberrypi -X mousepad
In this tutorial, we saw how to enable X11 forwarding for SSH sessions on a Raspberry Pi system. For users that choose to administer their Raspberry Pi via SSH, enabling X11 forwarding will make their lives easier by allowing them to control some GUI applications from their remote PC.