Friday, February 10, 2012

CentOS SSH X11 Forwarding

SkyHi @ Friday, February 10, 2012
To setup SSH X11 forwarding on CentOS, we need to:
0. To install KDE Desktop, type this:
yum groupinstall "X Window System" "KDE (K Desktop Environment)"
To install Gnome Desktop, type this:
yum groupinstall "X Window System" "GNOME Desktop Environment"
After the installation is finished, type this to start KDE or GNOME:
1. On the remote server, edit /etc/ssh/sshd_config, and set the following values:
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
2. On the remote server, install the package xorg-x11-xauth:
# yum install xorg-x11-xauth
3. On the remote server, install the fontconfig packages:
# yum install fonts-xorg-base (CentOS 4)
# yum install xorg-x11-fonts-base liberation-fonts (CentOS 5)
4. Now login to the remote server using "-Y" option:
local$ ssh -Y remote_server
5. In the remote server, run your X program, such as the xterm:
remote$ xterm
And you shall see the X program pop up in your local desktop.
You can also add the following into your $HOME/.ssh/config:
ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes
6. service sshd restart

Requirements for Remotely Displaying Applications

In order to run an application on one Linux system and have it display on another system there are a couple of prerequisites.
Firstly, the system on which the application is to be displayed must be running an X server. If the system is a Mac OS X, UNIX orLinux based system with a desktop environment running then this is no problem. If the system is running Windows, however, then you must install an X server on it before you can display applications from a remote system. A number of commercial and free Windows based X servers are available for this purpose and a web search should provide you with a list of options.
Secondly, the system on which the application is being run (as opposed to the system which the application is to be displayed) must be configured to allow SSH access. Details on configuring SSH on a CentOS system can be found in the chapter entitledConfiguring CentOS Remote Access using SSH. Finally, SSH must be configured to allow X11 Forwarding. To verify this, load the/etc/ssh/ssh_config file into an editor and make sure that the following directive is set:
X11Forward yes
Once the above requirements are met it is time to remotely display an application.

Remotely Displaying a CentOS Application

The first step in remotely displaying an application is to move to the system where the application is to be displayed. At this system, ssh into 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 ssh that we plan to tunnel X traffic through the connection:
ssh -X user@hostname
In the above example username 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. Once logged in, run the following command to see the DISPLAY setting:
The command should output something similar to the following:
To display an application simply run it from the command prompt. For example:
When run, the above command should run the gedit tool on the remote system, but display the output on the local system.

Trusted X11 Forwarding

If the /etc/ssh/ssh_config file on the remote system contains the following line, then it is possible to use trusted X11 forwarding:
ForwardX11Trusted yes
Trusted X11 forwarding is slightly faster than untrusted forwarding since it does not engage the X11 security controls. The -Y flag is needed when using trusted X11 forwarding:
ssh -Y user@hostname

Compressed X11 Forwarding

When using slower links the X11 data can be compressed using the -C flag:
ssh -X -C user@hostname