Introduction: Use SSH and XMing to Display X Programs From a Linux Computer on a Windows Computer

About: Hi, I'm psymansays. I'm an engineer from California. I enjoy sunsets, and long robot test drives on the beach. More from me:

 If you use Linux at work, and Windows at home, or vice versa, you might at times need to log in to the computer at your other location, and run programs. Well, you can install an X Server, and enable SSH Tunneling with your SSH Client, and one-up both VNC and Remote Desktop, for speed and usability.

This 'ible covers using and as your Windows solutions, and Openssh for the Linux side. On a side note, all of this can also make use of LogMeIn Hamachi as an easy-to-use VPN.

Step 1: Set Up Your SSH Client

In this step, we'll set up your SSH Client. First, install your copy of Bitvise Tunnelier, and start it up. You can create a connection profile with the Linux server's IP address or hostname, and optionally automatic login information. The next part of this step is filling out the ports to be forwarded via SSH. For the Windows X Server, we'll forward the linux box's port 6010 to the windows box's port 6000, where XMing will run. This way, Linux's own X Server can run undisturbed, at port 6000.

Step 2: Install XMing, the X Server for Windows

 Run the installer program for XMing. Next, start up XMing in the background. You can skip the configuration options, as the defaults should be fine.

Step 3: Make Sure That OpenSSH Is Installed on Linux

 On your Linux Computer, make sure that OpenSSH is installed and running. For Ubuntu, you can simply run "sudo apt-get install openssh-server" in the command terminal. Other Linux Distributions will differ.

Step 4: Add an Automatic "DISPLAY" Variable for the Linux Computer

Add the following lines to the end of the file in "${HOME}/.bashrc":

if [ -d "${HOME}/bin" ] ; then
 export  PATH="${PATH}:${HOME}/bin"
 if [ -f "${HOME}/bin/ssh_login" ] ; then
  . "${HOME}/bin/ssh_login"
Next, create the file "${HOME}/bin/ssh_login". Create the file with the following initial contents:


if [ -n "${SSH_CLIENT}" ] ; then
 if [ -z "${DISPLAY}" ] ; then
  export DISPLAY='localhost:10'

After saving the file, run the following command: "chmod 777 ${HOME}/bin/ssh_login" to make the script executable. What this does, is points any X program started from a console that is logged in via SSH to the port that re-directs back to the SSH-Client PC, in this case, the Windows PC running XMing. This just saves us from typing the same "DISPLAY=" line every time you log in via SSH.

Step 5: Start Your SSH Client.

 Start your SSH Session by clicking the "Login" button. After the initial authorization completes, and you accept any Encryption keys you need to, you'll likely have a command prompt window and a secure ftp window open. You can close the sFTP window, for now. To test your setup, run "xeyes" from the command prompt. If you see two big googley eyes following your mouse, with an X-Windows icon and window bar above them, then your setup is working!

Step 6: Linux-to-Linux Version

 As an extra step, If you are trying to perform the same type of thing from a Linux Client, to a separate Linux server, that's very simple. Each computer should have openSSH Client and Server installed. On one of the computers, just run "ssh -l -Y". The "-X" and "-Y" options enable X Server forwarding, just like that, but the "-Y" option enables more server features than "-X" does.

The "-l " option lets you specify the user server computer's user with which to log in, in case there is no identical user to the username you're logged in with on the client PC.