Showing posts with label X11. Show all posts
Showing posts with label X11. Show all posts

Thursday, May 6, 2021

LINUX AIO - How To Configure X11 Forwarding Using SSH In Linux

How To Configure X11 Forwarding Using SSH In Linux

 

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/sshd_config" file using your favorite editor:

# vi /etc/ssh/sshd_config

Add/modify following line:

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

Configure X11 Forwarding Using SSH In Linux

Press ESC key and type :wq to save and 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 root@192.168.225.52

Here, -X option is used to enable X11 forwarding over SSH. Replace "root@192.168.225.52" 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.

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!