In order to use graphical applications on a Linux machine, it doesn’t need to run the X-server itself. This means that it is possible to use graphical tools on a machine that doesn’t even have a graphical interface installed or even a machine without a video card and keyboard/mouse connected.
When installing servers, it’s not interesting to run a graphical interface on every machine. Besides taking unnecessary resources. Every process that we can eliminate improves performance and security. The X-server isn’t really an example of a stable or secure piece of software so we would like to avoid it on servers.
Also for a machine that is running somewhere else, and it’s never accessed locally, it could be interesting to be able to remotely use a graphical interface without the need for a running GUI.
The X-window system is designed (a long time ago) in such a way that the above scenario isn’t hard at all. It basically consists out of two components: the server and the client. In this case, these names are rather confusing because the client is usually running on a remote server and the server is the part running on a normal desktop. The server is the piece that actually displays (output) the application and takes input from the mouse/keyboard and sends it to the client.
The above image (hopefully) explains the concept a little better. Desktop is the only machine that runs a graphical interface. On the server, X isn’t even installed. Desktop displays X-clients as they would run locally on the server, only the input and output is handled by the X-server running on the desktop. The process of forwarding an X-client to a not-local X-server is called X-forwarding.
The X-server doesn’t have to run on the same operating system as the client. It is perfectly possible to display a Linux application in a Windows workstation as it would be running locally. This is where it becomes powerful to use X-forwarding.
Configure the remote Linux machine to allow X11-forwarding
The only package which is basically required on the remote machine (without GUI) is xauth. This allows authentication on the remote side. Of course we will also need at least one client-application to display on the other machine. I will use xclock which is part of package x11-apps as an example.
Check if both packages are installed:
Red Hat/CentOS/…
[jensd@cen ~]$ rpm -qa|egrep "xauth|xorg-x11-apps" xorg-x11-apps-7.6-6.el6.x86_64 xorg-x11-xauth-1.0.2-7.1.el6.x86_64
Debian/Ubuntu/…
jensd@deb:~$ dpkg --get-selections |egrep "xauth|x11-apps" x11-apps install xauth install
If they’re not installed, do so:
Red Hat/CentOS/…
[jensd@cen ~]$ sudo yum install xauth xorg-x11-apps
Debian/Ubuntu/…
jensd@deb:~$ sudo apt-get install xauth x11-apps
To be able to do X11-forwarding, SSH needs to let us do that. By default, Debian and Red Hat/CentOS allow X11-forwarding so there is little to do.
In order to verify if ssh allow X11-forwarding, check if the file /etc/ssh/sshd_config contains X11Forwarding yes:
jensd@deb:~$ sudo grep "X11Forwarding" /etc/ssh/sshd_config X11Forwarding yes
If there is no line for X11Forwarding or the line says no, add or change it and check the result again. After changing sshd_config, sshd needs to be restarted:
Red Hat <=6/CentOS <=6/Debian/… (init):
jensd@deb:~$ /etc/init.d/sshd restart
Red Hat >=7/CentOS >=7/Fedora/… (systemd):
[jensd@cen ~]$ systemctl restart sshd.service
That should be all on the remote machine’s side…
X11 forwarding to another Linux machine
Imagine the above scenario with two Linux machines. One being the desktop, running a GUI and thus X-windows and another, somewhere remote, the server, not running any graphical interface at all.
When you are already running an X-server on the desktop, there is nothing to configure in order to display a remote client. Just ssh with option -X to the remote machine a start a graphical application with the SSH-session:
X11 forwarding between to a Windows machine
Windows doesn’t have an X-server by default but fortunately, it exists and can be installed. The most popular X-server for Windows is Xming. You can download it form here: http://sourceforge.net/projects/xming/ installation should be quite simple.
After installing Xming, start it as any other application. Xming, by default, doesn’t display anything but starts in the notification area (near the clock) and waits for incoming requests.
To connect to a remote server, similar to using ssh -X on Linux, we need to tell putty to allow X11-forwarding. This can be found at the following place:
Leave all other options as you prefer them, connect to the remote machine and start a graphical application via SSH:
After following the above steps and examples, you should be able to use graphical programs on a remote machine without actually have anything graphical on that machine installed.
Pingback: Install and use CentOS 8 or RHEL 8 as KVM virtualization host | Jensd's I/O buffer