Running Graphical Linux Programs Remotely (X Forwarding)

Tags linux remote

Using the X Window System (also known as X11 or just X), you can run graphical programs on a remote Linux machine through an SSH connection. In order to do this, you will need to have an SSH connection to a machine that supports X forwarding with a client that also supports X forwarding, as well as an X server installed and running. Please note that depending on your local computer’s speed and especially your network connection, this can be very slow. 

In this guide, we use Colossus and Guardian as examples. These computers are for students to perform coursework remotely on a Linux machine and are configured to not require a VPN connection. Please note that you must have the VPN installed and connected in order to start an SSH connection and use X forwarding to other fully managed Linux systems. Please visit the Related Articles section for information about connecting to the VPN.

Xpra is a program with similar functionality to X forwarding, but much faster and with helpful additional features. X forwarding should be avoided unless for convenience or if an application does not work through Xpra. Please visit our KB article for more information about using Xpra.

From a Linux Computer

Almost all distributions will support this out of the box.  Even if you run Wayland (in distros such as Fedora), XWayland provides backward compatibility with X.  To do this, use the -X flag with your SSH command: ssh -X username@computername

XWayland screen

Programs launched through X forwarding will usually have a message like this in the title bar saying “(on computername)” to help distinguish that it is running through X forwarding. Your mileage may vary depending on your choice of desktop environment/compositor/implementation of X/etc. The following screenshot was taken on Fedora 31 running Gnome 3.34.4

X forwarding message that reads, xclock (on colossus.it.mtu.edu)

From a Windows Computer

From Windows, you need to have an SSH client and an X server installed, as these are not installed by default on Windows.  Two popular methods are 

  • Using MobaXterm, which is a new, feature-rich client 
  • Using PuTTY with Xming, as PuTTY is a popular SSH client for Windows

Using MobaXterm

MobaXterm is a cool terminal emulator with a ton of features. The home edition is free for use. MobaXterm is available to download.

  1. Once installed, open MobaXterm.  It will be a little slow for the first launch.  If you get a prompt for firewall access, select Allow access.
  2. Start a new session by selecting Session.
    MobaXterm window
  3. In the window that pops up, select SSH, then enter the computer you wish to connect to in the Remote host field. You can check the box for Specify username and enter your username as well. Leave the port set to 22.

  4. Select the Advanced SSH settings tab and then make sure the X11-Forwarding box is checked.  Leave the rest of the settings at their defaults. Select OK
    Session settings window

  5. MobaXterm will start a new SSH session in a tab and prompt for your password.  Once authenticated, MobaXterm will display a message with information about the session, followed by any information from the connected computer. From here, you can run commands and open programs normally. MobaXterm will add “@computername” to the title bar of any windows that pop up to show that they are running from an X session.
    MobaXterm session window

  6. From here, you can quickly use the saved user session to reconnect again. The tabs along the left have useful tools, games, and more. The SFTP tab also has an SFTP file browser for quick and easy file transfers between your Michigan Tech home drive and the computer running MobaXterm.

Using PuTTY with Xming

Xming Download Site

Putty Download Site

  1. Make sure Xming is running; the Xming icon will show in the System Tray if it's active.
    Xming icon in System Tray
  2. With PuTTY running, scroll down to Connection, then expand SSH and select the X11 tab. Check the box for Enable X11 forwarding.
    PuTTY SSH tab

  3. Scroll back up, select Session at the top and enter a Host Name. Enter a name in the box below Saved Sessions, such as the name of the computer you’re connecting to and select Save.

    Putty Configuration window

For a quick way to load these settings and then connect, you can double-click on the saved session in the future.  Alternatively, click on the saved entry, choose Load, then Open

Once the terminal session starts, you will be able to launch programs from the command line.  Xming will distinguish remote programs by putting its icon on any windows that open through X forwarding.

From macOS

X11 is no longer included with Mac, but X11 server and client libraries are available from the XQuartz project. Download and install the latest XQuartz release.

From the XQuartz terminal window, run the following: ssh -X username@computername
XQuartz terminal window with command line

Once connected, you can run any program that utilizes X forwarding.

Here is an example of what running xclock looks like from a Mac:

xclock

Programs can be quit by closing the window or by pressing CTRL + C in the XQuartz terminal

X Forwarding Between Two Macs

If you would like to utilize X11 between two macOS computers, XQuartz must be installed on both and the following etc/ssh/sshd_config settings must be configured on the Mac from which you wish to enable X11 forwarding. 

Please also note that macOS has very limited support for acting as a host for X forwarding programs. Many programs by Apple or those exclusive to macOS may not have support to run in this manner. 

Procedure

  1. From the Terminal app, make sure you su username-adm
    terminal window su username-adm
  2. Run sudo vim /etc/ssh/sshd_config
    terminal window command line

  3. Add these two lines to the file:
    X11Forwarding yes
    X11DisplayOffset 10

  4. Save and quit the file. You may need to restart sshd by performing the following commands:
    sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist 
    sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist​​​

     

Was this helpful?
0 reviews

Details

Article ID: 103526
Created
Mon 3/30/20 10:04 AM
Modified
Tue 6/14/22 11:35 AM

Related Articles (3)

Instructions for installing and running the VPN client (f5) on computer running Linux
Instructions for installing and running the VPN client on a computer running macOS
Instructions for installing and running the VPN client on a Windows computer