How to Enable X11 Forwarding on Raspberry Pi?


This post may contain affiliate links/ads and I may earn a small commission when you click on the links/ads at no additional cost to you. As an Amazon Affiliate, I earn from qualifying purchases. Techsphinx also participates in the StationX Affiliate program. You can read my full disclaimer here.

In this guide, I will show you how to enable X11 Forwarding over SSH on Raspberry Pi and access remote graphical applications from Windows and Linux.

SSH (Secure Shell) protocol enables a user to connect to a system and perform tasks on it remotely. However, SSH only provides access to the shell, this means you can only use the command-line interface (CLI) to perform tasks on the remote system.

So, what if you need to open any GUI (Graphical user interface) application? This is where X11 forwarding comes to play.

X11 forwarding allows a user to forward the remote application display to the client machine. After you enable X11 forwarding on Raspberry Pi, you can start any GUI application and forward its graphical interface to the client device.

Equipment Needed

Alternatively, you can purchase CanaKit Raspberry Pi 4 Extreme Kit that contains all the above-mentioned items.

Pre-Requisites to enable X11 forwarding on Raspberry Pi

  • Raspberry Pi OS installed and running.
  • Active internet connection to download the required software.
  • Sudo privileges on Raspberry Pi and the client Linux Machine.
  • SSH service enabled on Raspberry Pi.

If you don’t know how to enable SSH, then you can check out my guide on “how to enable SSH on Raspberry Pi” before proceeding.

Setup X11 Forwarding on Raspberry Pi

You don’t have to install any package to use the X11 window forwarding. You just have to enable the X11 Window Forwarding in the SSH config files.

On Raspberry Pi OS, X11 Window Forwarding is enabled by default. If it is not in your case, then follow the below steps to enable it:

1. Open the terminal.

2. Open the “sshd_config” file. I am using the Nano command-line text-editor to open and edit the file.

sudo nano /etc/ssh/sshd_config

3. Find the line that says “X11 forwarding”, uncomment the line (remove # from the beginning) and make sure it is set to “yes”.

enable X11 forwarding on Raspberry Pi

4. Save and close the file. In Nano, use the Ctrl + x key combination to exit the file and when it asks to save choose “yes”.

5. Restart the SSH service.

sudo systemctl restart ssh

That’s it, X11 Window Forwarding is now enabled on your system.

Connect to Raspberry Pi via X11 Forwarding

You can connect to Raspberry Pi using X11 forwarding from Windows and Linux.

Connecting from Windows

You’ll need 2 tools to connect to Raspberry Pi via the X11 Window Forwarding – PuTTY and Xming

1. Download and install both PuTTy and Xming.

2. Launch Xming, then launch PuTTY and fill in the IP address of the Raspberry Pi.

Connect using PuTTY SSH client

3. Now, navigate to Connection > SSH and enable the X11 Window Forwarding.

4. Click on the “Open” button, and a new PuTTy session will be opened.

Enable X11 forwarding on PuTTY

5. Log in to the Raspberry Pi by providing the username and password of any user on the Pi. I am using the default “pi” user here.

Log in using PuTTY from Windows

6. Now, you can open an X session of any program. Just type the name of the program that has a graphical user interface (GUI).

For example:

To run VLC media player run the command:

vlc
Running VLC over X11 Forwarding Windows

To start Thonny Python IDE run the command:

thonny
Running Thonny over X11 Forwarding Windows

Connecting from Linux

To connect from Linux, you don’t need to install any programs, the ssh client is pre-installed on most Linux systems. Just use the “-X” option for an X-window session.

ssh -X USER@IPADDRESS

(Replace USER and IPADDRESS with the actual username and IP address of Raspberry Pi)

Connecting to Raspberry Pi with X11 forwarding

Once, you are connected via SSH, you can run any graphical application on Pi and the screen will appear through the X11 Window forwarding.

Just type the name of the program that has a graphical user interface (GUI).

For example:

To run VLC media player run:

vlc
Running VLC over X11 Forwarding Linux

To start Thonny Python IDE run:

thonny
Running Thonny over X11 Forwarding Linux

Other ways to connect to Raspberry Pi Remotely

There are other ways to remotely connect to Raspberry Pi apart from using the X11 Window Forwarding over SSH. I have written various guides for the same.

Here are links to those guides:

1. Connect to Raspberry Pi using remote desktop

2. Connecting to Raspberry Pi using VNC

You can use any of these utilities or protocols to remotely connect to the Raspberry Pi.

Conclusion

That’s it for connecting to Raspberry Pi via X11 Forwarding over SSH. If you have any questions, then feel free to ask them in the comments.

Also, you can check out my other articles/guides related to Raspberry Pi here.

If you like this post, then follow Techsphinx on Facebook and Twitter for more reviews, tricks, tips and tutorials.

This article needs update or correction? Report the issue here so I can update it.


Like it? Share with your friends!

Rahul R Nair

Rahul is obsessed with technology and electronic devices. He is also the founder of TechSphinx. Being a technophile, he is always busy doing some techy stuff or learning about the latest technologies. When not busy with his usual routine (staring at the computer screen) he likes to write and share his knowledge with the world.
Subscribe
Notify of
guest
3 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
3
0
Would love your thoughts, please comment.x
()
x