x11-port-forwarding-raspberry-pi

What is X11 Port Forwarding and How to Use It on Raspberry Pi

  • 3 min

When working with a Raspberry Pi, you may sometimes need to run graphical applications remotely, that is, from a machine different from the one running the software.

In these cases, it is common to use some type of remote desktop like VNC. However, in certain situations we won’t be able to connect via a full remote desktop. For example, due to lack of permissions or not wanting to install additional software on the machine.

In these cases, X11 port forwarding can be an interesting alternative to redirect the graphical interfaces of your applications to your local device, allowing you to work with them as if they were running locally.

What is X11 Port Forwarding

X11 port forwarding is a technique that allows redirecting the graphical interface of applications running on a remote server to a local client. It uses the X Window System (X11) to display the graphical interface of applications on a remote machine.

X11 port forwarding via SSH (Secure Shell) allows redirecting X11 connections through a secure SSH tunnel. It is commonly used to run graphical applications from remote servers on Unix and Linux systems.

Configuring X11 Port Forwarding

First, we ensure that the SSH server on our Raspberry Pi is configured to allow X11 forwarding. We verify and modify this configuration in the SSH configuration file (/etc/ssh/sshd_config).

Open the SSH configuration file with the following command:

sudo nano /etc/ssh/sshd_config

Make sure the following lines are not commented out and are configured correctly:

X11Forwarding yes X11DisplayOffset 10

Finally, save the changes and restart the SSH service to apply the new configuration with:

sudo systemctl restart ssh

Running Graphical Applications

On the other hand, the client machine must run an SSH application that is compatible with X11 Port Forwarding. Most of the ones we’ve seen, like Putty, mRemoteNG, and MobaXTerm are all compatible.

For example, in the case of Putty, it is an option we must check in Connection/SSH/X11.

putty-ssh-x11-forwarding

Once connected, you can run graphical applications from your Raspberry Pi’s command line, and their interfaces will appear on your local machine. To test X11 Port Forwarding you can run any application that has a graphical interface.

Or, if you want to do a test, run the X11 Apps.

sudo apt install x11-apps

And then,

xclock &