In today’s guide, we will look at how to enable SSH X11 forwarding on a Linux server. The first method will be forwarding through an additional Linux (Gateway) server. In second method we will directly connect to a Linux server with GUI.
Method 1: X11 Tunnel
First, connect to machine B and forward [localPort] to C:22 through
A$ ssh -L [localPort]:C:22 B A$ ssh -X -p [localPort] localhost
Now we can run X11 programs on C and have them display on A
My Desktop Machine - 192.168.107.100 My Gateway server - 10.56.1.100 Some Linux server - 10.56.107.1
First, connect to machine B and forward [localPort] to C:22 through B
From the Ubuntu desktop Machine
$ ssh -L 67453:10.56.107.1:22 10.56.1.100
$ ssh -X -p 67453 localhost
Now we can run X11 programs on 10.56.107.1 and have them display on 192.168.107.100
Method 2: X11 Forwarding
Install only the required X11 package
# yum -y install xorg-x11-xauth xorg-x11-fonts-* xorg-x11-utils
To verify the forwarding install any GUI apps, In my case going with Scap Workbench to customize security standards.
# yum -y install scap-security-guide scap-workbench
SSH into the remote server with
# ssh -X root@servera
Run the scap-workbench command
Now we are able to launch the Scap workbench on a remote server and forward the graphical interface back to the local Linux desktop.
In case, If still you have challenge related to listening on interface
Edit the sshd_config and make the below changes.
# grep -i "AddressFamily" /etc/ssh/sshd_config # sed -i "s/#AddressFamily any/AddressFamily inet/g" /etc/ssh/sshd_config
Validated the change.
# grep -i "AddressFamily" /etc/ssh/sshd_config
Reload the config change for SSH service.
# systemctl reload sshd
That’s it, we are done with X11 forwarding.