How to Do X11 Forwarding in Linux: A Beginner’s Guide

Siva
2 min readApr 30, 2023

X11 forwarding is a powerful feature in Linux that allows you to run graphical applications on a remote Linux server and display them locally on your machine. This can be incredibly useful for tasks such as software development or managing a remote server. In this article, we will explore how to do X11 forwarding in Linux.

Prerequisites

To follow along with this tutorial, you will need:

  1. A local machine running Linux with an X11 server installed.
  2. A remote machine running Linux with an X11 server installed and an SSH server running.
  3. SSH client installed on the local machine.

Step 1:

Connect to the remote server via SSH The first step is to connect to the remote server via SSH. Open a terminal window on your local machine and enter the following command:

$ ssh -X username@remote_server

Replace ‘username’ with your username on the remote server, and ‘remote_server’ with the IP address or hostname of the remote server.

Step 2:

Test X11 forwarding Once you have connected to the remote server, you can test X11 forwarding by running a graphical application on the remote server and displaying it on your local machine. To test this, we will use the xclock application, which displays a clock on the screen.

Enter the following command on the remote server:

$ xclock

If everything is set up correctly, you should see a clock displayed on your local machine.

Step 3:

Troubleshooting If X11 forwarding doesn’t work, there are a few things you can try to troubleshoot the issue.

First, make sure that X11 forwarding is enabled on both the local and remote machines. To check if it is enabled on the remote server, open the ssh_config file on the remote server and make sure the following line is present and not commented out:

X11Forwarding yes

To check if it is enabled on the local machine, run the following command:

$ echo $DISPLAY

If you see output that looks like “localhost:10.0”, X11 forwarding is enabled on your local machine.

If X11 forwarding is enabled on both machines, make sure that you are using the -X option when connecting to the remote server via SSH. This option tells SSH to enable X11 forwarding.

If you are still having issues, check that the xauth package is installed on both the local and remote machines. This package is required for X11 forwarding to work properly.

Conclusion

X11 forwarding is a powerful feature in Linux that allows you to run graphical applications on a remote server and display them locally. By following the steps outlined in this article, you can easily set up X11 forwarding and start using it to run graphical applications on a remote server. If you run into any issues, be sure to troubleshoot using the steps outlined in this article.

--

--