Posted: 2024-02-28
In the previous chapter, we looked at how to display the entire AlmaLinux 9 desktop on a remote computer. While this works well if you need to display the entire desktop remotely, it could be considered overkill if you only want to display a single application. Therefore, this chapter will look at displaying individual applications on a remote system.
Requirements for Remotely Displaying AlmaLinux 9 Applications
There are some prerequisites to running an application on one AlmaLinux 9 system and displaying it on another. First, the system on which the application is to be displayed must be running an X server. If the system is a Linux or UNIX-based system with a desktop environment running, then this is no problem. However, if the system is running Windows or macOS, you must install an X server on it before you can display applications from a remote system. Several commercial and free Windows-based X servers are available for this purpose, and a web search should provide you with a list of options.
Second, the system on which the application is being run (as opposed to the system on which the application is to be displayed) must be configured to allow SSH access. Details on configuring SSH on an AlmaLinux 9 system can be found in the chapter Configuring SSH Key-based Authentication on AlmaLinux 9. This system must also run the X Window System from X.org instead of Wayland. To enable the X.org system from within the desktop, log out of the Gnome desktop, select your user account from the login screen, and then click the settings button in the bottom right-hand corner of the screen:
Select the Standard (X11 display server) option from the menu before logging in as usual. To revert to Wayland, repeat these steps, selecting the Standard (Wayland display server) option from the login screen settings menu.
You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.
Full book includes 34 chapters and 290 pages. Learn more. |
Another option is to edit the /etc/gdm/custom.conf file, uncomment the WaylandEnable line as follows and restart the system:
# Uncomment the line below to force the login screen to use Xorg
WaylandEnable=false
Code language: plaintext (plaintext)
Once you have logged back into the desktop, open a Terminal window and run the following command to confirm that the X.org system has been enabled:
$ echo $XDG_SESSION_TYPE
Code language: plaintext (plaintext)
The above command will output either x11 or wayland, depending on the current configuration.
Finally, SSH must be configured to allow X11 forwarding. This is achieved by adding the following directive to the SSH configuration on the system from which forwarding is to occur. By default on AlmaLinux 9, the /etc/ssh/sshd_config file contains a directive to include all of the configuration files contained in the /etc/ssh/sshd_config.d directory:
Include /etc/ssh/sshd_config.d/*.conf
Code language: plaintext (plaintext)
Create a new file in the /etc/ssh/sshd_config.d folder named 05_x11forwarding and edit it to enable the X11Forwarding property is enabled as follows:
You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.
Full book includes 34 chapters and 290 pages. Learn more. |
X11Forwarding yes
Code language: plaintext (plaintext)
After making the change, save the file and restart the SSH service:
# systemctl restart sshd
Code language: Kotlin (kotlin)
Once the above requirements are met, it should be possible to display an X-based desktop application remotely. Keep in mind that not all GNOME apps are compatible with X11 forwarding. If an app is incompatible, the following error will appear when you try to run it using X11 forwarding: X11 connection rejected because of wrong authentication.
Displaying an AlmaLinux 9 Application Remotely
The first step in remotely displaying an application is to move to the system where the application is to be displayed. At this system, establish an SSH connection to the remote system so that you have a command prompt. This can be achieved using the ssh command. When using the ssh command, we need to use the -X flag to tell it that we plan to tunnel X11 traffic through the connection:
$ ssh -X user@hostname
Code language: plaintext (plaintext)
In the above example, user is the user name to use to log into the remote system, and hostname is the hostname or IP address of the remote system. Enter your password at the login prompt and, once logged in, run the following command to see the DISPLAY setting:
Displaying AlmaLinux 9 Applications Remotely (X11 Forwarding)
You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.
Full book includes 34 chapters and 290 pages. Learn more. |
$ echo $DISPLAY
Code language: plaintext (plaintext)
The command should output something similar to the following: localhost:10.0
To display an application, run it from the command prompt. For example:
$ gedit
Code language: plaintext (plaintext)
When executed, the above command should run gedit on the remote system but display the user interface on the local system.
Trusted X11 Forwarding
You can also enable trusted X11 forwarding by adding the following line to the 05_x11forwarding and restarting the ssh server:
ForwardX11Trusted yes
Code language: plaintext (plaintext)
Trusted X11 forwarding is slightly faster than untrusted forwarding but is less secure since it does not engage the X11 security controls. The -Y flag is needed when using trusted X11 forwarding:
You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.
Full book includes 34 chapters and 290 pages. Learn more. |
$ ssh -Y user@hostname
Code language: plaintext (plaintext)
Compressed X11 Forwarding
When using slower connections, the X11 data can be compressed using the ssh -C flag to improve performance:
$ ssh -X -C user@hostname
Code language: plaintext (plaintext)
Displaying Remote AlmaLinux 9 Apps on Windows
To display AlmaLinux 9-based apps on Windows, an SSH client and an X server must be installed on the Windows system. Installing and using the PuTTY client on Windows was covered earlier in the book in the “Configuring SSH Key-based Authentication on Rocky Linux 9AlmaLinux 9”maLinux 9” chapter. Refer to this chapter if you have not already installed PuTTY on your Windows system.
In terms of the X server, several options are available, though a popular choice appears to be VcXsrv which is available for free from the following URL:
https://sourceforge.net/projects/vcxsrv/
Once the VcXsrv X server has been installed, an application named XLaunch will appear on the desktop and in the start menu. Start XLaunch and select a display option (the most flexible being the Multiple windows option which allows each client app to appear in its own window):
You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.
Full book includes 34 chapters and 290 pages. Learn more. |
Click the Next button to proceed through the remaining screens, accepting the default configuration settings. On the final screen, click the Finish button to start the X server. If the Windows Defender dialog appears, click the button to allow access to your chosen networks.
Once running, XLaunch will appear in the taskbar and can be exited by right-clicking on the icon and selecting the Exit… menu option:
With the X server installed and running, launch PuTTY and either enter the connection information for the remote host or load a previously saved session profile. Before establishing the connection, however, X11 forwarding needs to be enabled. Therefore, within the PuTTY main window, scroll down the options in the left-hand panel, unfold the SSH section, and select the X11 option, as shown in Figure 17-4:
Displaying AlmaLinux 9 Applications Remotely (X11 Forwarding)
Turn on the Enable X11 forwarding checkbox highlighted in Figure 17-5, return to the sessions screen, and open the connection (saving the session beforehand if you plan to use it again):
You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.
Full book includes 34 chapters and 290 pages. Learn more. |
Log into the AlmaLinux 9 system within the PuTTY session window and run a desktop app. After a short delay, the app will appear on the Windows desktop in its own window. Any dialogs the app opens will also appear in separate windows, just as they would on the AlmaLinux 9 GNOME desktop. Figure 17-6, for example, shows the AlmaLinux 9 nm-connection-editor tool displayed on a Windows 11 system:
Summary
For situations where remote access to individual AlmaLinux 9 desktop applications is required as opposed to the entire GNOME desktop, X11 forwarding provides a lightweight solution to remotely displaying graphical applications. The system on which the applications are to appear must be running an X Window System-based desktop environment (such as GNOME) or have an X server installed and running. Once X11 forwarding has been enabled on the remote server and a secure SSH connection established from the local system using the X11 forwarding option, most applications can be displayed remotely on the local X server.