Authors Top

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

1. Overview

The secure shell (SSH) is a handy tool for running remote processes on a local Linux system. Inevitably, while using SSH, we encounter the need to display graphical interfaces from the remote system on our local screen. X11 port forwarding/tunneling facilitates this seamlessly and securely.

In this article, we’ll learn how to configure X11 port forwarding.

2. X Forwarding Configuration

For clarity, we’ll use the terms server and client to reference the remote and local Linux systems, respectively. The server must be able to perform X server authorization for X forwarding to work. In addition, we must enable X forwarding on both the server and the client systems. Let’s see how to perform each of these steps in detail.

2.1. X Server Authorization

We need to confirm that xauth is installed on the server for X forwarding to work. The xauth utility handles authorization of the X server information on UNIX systems. Let’s quickly check whether it is installed:

$ which xauth
/usr/bin/xauth

Luckily, xauth comes installed in most standard Linux systems. In Section 3, we shall see how to install it if needed.

2.2. Enabling X Forwarding on Server

To enable X forwarding on the server-side, we simply add the X11Forwarding keyword with a yes argument to the /etc/ssh/sshd_config script:

X11Forwarding yes

2.3. Enabling X Forwarding on the Local System

Once we have enabled X-forwarding on the server, we can now run the usual SSH command with an additional -X option:

ssh -X [email protected]

Now, we can simply interact with graphical interfaces in our local system, while their processes run on the remote server.

Alternatively, we can write an explicit version of the command which uses the ForwardX11 keyword. Note the difference in this ForwardX11 keyword used on the client-side as compared to the X11Forwarding we used on the server-side.

$ ssh -o ForwardX11=yes [email protected]

Moreover, to set X forwarding as the default behavior whenever we SSH, let’s edit the SSH configuration file; ~/.ssh/config file and add the ForwardX11 keyword to the file:

FowardX11 yes

The above information is all we require in order to display remote GUIs on our local Linux system with SSH.

3. Diagnosing X Forwarding Errors

Here, we identify some methods that we can use to diagnose errors when running X forwarding configurations.

3.1. Installing xauth

Installing xauth is straightforward, in rare cases where it is not already installed. For example, assuming our server runs Debian/Ubuntu Linux, we can easily install xauth:

sudo apt-get install xauth

Similarly, we can use yum on other Linux distributions, e.g., Fedora:

$ yum search xauth 
$ yum install xorg-x11-xauth

3.2. Missing Display

First, let’s figure out how to set the DISPLAY environment variable on the server. For context, we note that Linux systems can run multiple displays which are labeled by integers from 0 onwards. For instance, let’s check what displays are already set:

$ echo $DISPLAY
:0

In this case, X11 server authorization is set to use the first (signified by number 0) local display. In the case of a remote display, the IP address of our client system would be listed as a prefix to the colon:

$ echo $DISPLAY
client:10

We can, however, make sure that the X server used on the remote display does not interfere with the main X11 display on the server. Usually, the server sets this by default, but let’s do it by adding the X11DisplayOffset keyword in the /etc/ssh/sshd_config script on the server:

$ X11DisplayOffset 10

On the other hand, sometimes we might want to set all displays to be used remotely. We do this on the server by simply adding the X11UseLocalhost keyword to /etc/ssh/sshd_config with a no argument:

X11UseLocalhost no

More information on this and related errors can be found here

4. Conclusion

In this article, we have explored the use of X forwarding to display Graphical User Interfaces remotely when SSH’ing to a server. This process is mostly straightforward. In addition, in the case where issues such as missing displays arise during the configuration, we have also checked out a few diagnosis tricks.

Authors Bottom

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

Comments are closed on this article!