How to enable X11 forwarding on Raspberry Pi

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
How to enable X11 forwarding on Raspberry Pi
How to enable X11 forwarding on Raspberry Pi
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Raspberry Pi
Software OpenSSH
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – 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.

DID YOU KNOW?
The X11 window 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. Openssh let 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 no.
  1. In case it is not already installed, install the OpenSSH Server package on your Raspberry Pi:
    $ sudo apt update
    $ sudo apt install openssh-server
    
  2. Using the terminal on your Raspberry Pi, open the sshd configuration file with nano or your preferred text editor. You will need to use root permissions (sudo) for this:
    $ sudo nano /etc/ssh/sshd_config
    
  3. In this file, scroll down until you find the following line, and then uncomment it by removing the # symbol in front of it.
    X11Forwarding yes
    

    Finding and uncommenting the X11 forwarding line in the SSH config file
    Finding and uncommenting the X11 forwarding line in the SSH config file




    Save your changes and exit the file when finished uncommenting the line.

  4. 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.

  5. From the remote system, use the following syntax with the -X option 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
    

Closing Thoughts




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.



Comments and Discussions
Linux Forum