Home Linux DistributionsCentOS How To Configure X11 Forwarding Using SSH In Linux
How To Configure X11 Forwarding Using SSH In Linux

How To Configure X11 Forwarding Using SSH In Linux

By sk
9715 Views

Today, we are going to learn a lesser known, interesting and useful feature about Linux. I am sure most of you know about SSH. We can access remote Linux systems securely via SSH. But, did you know that it is possible to forward X over SSH to run graphical applications remotely? Yes! This mechanism is known as X11 forwarding. In this guide, we are going to configure X11 forwarding using SSH in Linux.

What is X11 forwarding?

X11 forwarding is method of allowing a user to start a graphical applications installed on a remote Linux system and forward that application windows (screen) to the local system. The remote system need not to have X server or graphical desktop environment. Hence configuring X11 forwarding using SSH enables the users to securely run graphical applications over SSH session.

To put this in layman terms,

  • We connect to a remote system via SSH,
  • And then we launch a GUI application (which is installed in the remote system) from that SSH session,
  • Now, the GUI application runs on the remote system, but the application window appears on our local system. So we can use this remote GUI program on your local system as the way we use a locally installed program.

Clear? Now let us go ahead and see how to run remote GUI applications over SSH session.

Configure X11 Forwarding Using SSH In Linux

For the purpose of this guide, I will be using the following two systems:

  • Remote server - CentOS 8 minimal server (No GUI).
  • Local system - Ubuntu 20.04 LTS with Gnome DE.

Configuring X11 forwarding is trivial.

Make sure you have installed "xauth" on your remote serer system. If it is not installed, run the following command as root or sudo user:

# dnf install xorg-x11-xauth

Go to your remote system (in my case it is CentOS 8) and edit "/etc/ssh/ssh_config" file using your favorite editor:

# nano /etc/ssh/ssh_config

Add/modify following line:

[...]
X11Forwarding yes
Configure X11 Forwarding Using SSH In Linux

Configure X11 Forwarding Using SSH In Linux

Press Ctrl+O to save and Ctrl+X to close the file. Restart sshd service to effect the changes:

# systemctl restart sshd

Done! We have configured X11 forwarding.

Now go to your client system (in my case, it is Ubuntu 20.04) and access the remote server via SSH using command:

$ ssh -X [email protected]

Here, -X option is used to enable X11 forwarding over SSH. Replace "[email protected]" with your remote server's username and IP address.

You will see the following warning message at first time.

/usr/bin/xauth: file /root/.Xauthority does not exist

However, the .Xauthority file should be automatically generated during the first login, thus subsequent logins should be fine.

Next, launch any GUI applications from this SSH session. I already have installed Gedit graphical text editor in my CentOS 8 server, so I am going to launch it using command:

# gedit

The gedit GUI window screen will now appear in your local system.

Run remote graphical applications over SSH session in Linux

Run remote graphical applications over SSH session in Linux

You can interact with the Gedit application installed on the remote server using your local system's display, mouse, and keyboard.

Even though my CentOS 8 server doesn't have GUI desktop, I can be able to open Gedit graphical editor and use it from my local Ubuntu system. Here is the visual demo:

Configure X11 forwarding in Putty

If you use Putty client to access remote systems, enter your remote system's IP or hostname in the Session tab:

Connect to remote system using Putty

Connect to remote system using Putty

Next, navigate to Connection -> SSH -> X11 and enable X11 forwarding option. Click Open to establish a new Putty session:

Configure X11 forwarding in Putty

Configure X11 forwarding in Putty

Enter the username and password of the remote server. Once you connected to the remote system via Putty, launch any X application installed in the remote server.

Run graphical applications over Putty session

Run graphical applications over Putty session

Start interacting with the remote GUI application from your local system!

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

2 comments

BC September 13, 2020 - 3:35 am

How does typing ‘cat .Xauthority’ “create” a file with text in it?
What if ‘echo $DISPLAY’ doesn’t return anything?

Reply
sk September 13, 2020 - 2:31 pm

The .Xauthority file should be automatically generated during the first login, thus subsequent logins should be fine. So you don’t need to manually create the Xauthority file as mentioned in the guide. Also ignore the ‘echo $DISPLAY’ command. This was a mistake from my side. I updated the guide. Thanks.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More