X11 Forwarding through SSH enables a user to run a software application from a remote system using the CPU and memory of the remote system while rendering the GUI of the application locally. This can be very handy if your chosen desktop is Linux, Windows, or Mac (this tutorial will not cover Mac) but either the application is not cross platform or unavailable due to licensing, your local system does not have the local resources to run the chosen application, or you need access to network resources which are local to the target of the SSH connection but not local to the machine you are currently using (i.e. a server behind a firewall/gateway device that has port forwarding for SSH to the remote host to which you are connecting).

There are plenty of remote control software packages which would allow for full desktop rendering. Sometimes it's not necessary to display a full desktop. In a Microsoft Windows environment this would be most closely similar to the technology of RemoteApp.

X11 Forwarding is easy to setup and use. Best of all, X11 Forwarding through SSH is encrypted which means the entire SSH communication is encapsulated in a the SSH Session. This tutorial will assist in configuring the remote server to allow X11 Forwarding through SSH and will provide local commands or software needed to establish connection to the X11 Session through SSH.

 

The things you will need before starting:

  • A basic understating of Linux command line.
  • Access to a Linux or Windows Desktop and a Linux Server with GUI apps installed.
  • Access to the root account or an account with sudo access.
  • Basic knowledge of text editing software such as Vi, Vim, Nano, Pico, Gedit, etc.
  • Application Support
    Windows: PuTTY, Xming.
    Linux: GUI Desktop, Terminal

Enabling X11 Forwarding on the Server

  1. Log in as either root or a user with sudo access.
  2. The location the SSH Daemon configuration file
    Different Linux Distributions may locate them differently
    I use vim the most frequently, so my command will look like this:
    sudo vi /etc/ssh/sshd_config
  3. Edit the file in order to add the following parameter (add or find and edit)
    X11Forwarding yes
  4. Save and Close the file.
  5. Restart the SSH Daemon.
    Debian/Ubuntu:
    sudo /etc/init.d/ssh restart
    RedHat/CentOS/Fedora:
    service ssh restart
  6. Logout but take note of the hostname or IP address of the server.

X11 Forward in Linux

  1. Login to your local Linux Desktop and open a terminal
  2. Once open at a terminal enter the following command:
    Substitute the {} and contents of them with the Server Name or IP address of the SSH server configured in the previous section.
    ssh -X username@{Server Name or IP Address}
    or
    ssh -X -l username {Server Name or IP Address}
    -X
    indicates that you wish to enable X11 Forwarding for this session.
  3. Once you have connected to the SSH Server enter the commands to run the applications you wish to forward
    In this example I wish to run an instance of the firefox browser
    Type the following line to run the application
    firefox &
    The & sends the program to the back so that the SSH connection can continue to be used for other applications.
    Additional applications can be run through this single SSH session. Examples of other applications are:
    gimp &
    xcalc &
    libreoffice &
    xchat &
  4. If you close your terminal you will break the connection for the applications. Please close all applications first in to keep from losing data.

 X11 Forward in Windows using PuTTY and Xming

  1. Login to your local Windows Desktop. Make certain that your account is an administrator or that you have a username and password for an administrator account.
  2. Download Xming from SourceForge and install (I do not usually install the "portable PuTTY replacement package" because I usually already have PuTTY installed).
  3. Download PuTTY from the Official PuTTY site and install PuTTY.
  4. Once they are installed
    Open/Run Xming (Xming MUST be open in order to capture the X11 Session from PuTTY).
    Then open PuTTY.
  5. Type the "Host Name (or IP address)" of the server which was configured in the first section of this tutorial.
  6. On the left of the PuTTY Configuration Screen expand the [+] for SSH.
  7. Navigate to the X11 Configuration Page and then checkmark the [ ] for "Enable X11 forwarding".
  8. At this point you can "Open" the session or navigate back to the Session Page and Save your session.
  9. Once you choose "Open" you will see a PuTTY SSH session prompting for Username and Password.
  10. Once authenticated to the SSH Server enter the commands to run the applications you wish to forward
    In this example I wish to run an instance of the firefox browser
    Type the following line to run the application
    firefox &
    The & sends the program to the back so that the SSH connection can continue to be used for other applications.
    Additional applications can be run through this single SSH session. Examples of other applications are:
    gimp &
    xcalc &
    libreoffice &
    xchat &
  11. If you close your terminal you will break the connection for the applications. Please close all applications first in to keep from losing data.

You have now configured a server to allow for X11 Forwarding through SSH and connected through a SSH client on either Windows or Linux. This is possible on a local LAN or even over the WAN (depending on bandwidth).