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

Picture of Use SSH and XMing to Display X Programs From a Linux Computer on a Windows Computer

 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 sourceforge.net/projects/xming/ and www.bitvise.com/tunnelier 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

Picture of 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

Picture of 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

Picture of 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"
 fi
fi
Next, create the file "${HOME}/bin/ssh_login". Create the file with the following initial contents:

#!/bin/sh

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

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.

Picture of 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

Picture of 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.

Comments

co1973 (author)2010-04-12

Nice Instructable.  I used to use a similar process to confuse the heck out of people in the Sun Spark station lab in college.  Just rsh into someone else's machine in the lab, redirect the display to your own machine, and run a media player.  You should see the looks on people's face when the computer they're sitting at mysteriously starts to "moo" or play music...


ElegantAndrogyne (author)co19732014-04-10

There's a better way... SSH into the station, wget a nice file and use xmms2 or any other CLI player :)

psymansays (author)co19732010-04-13

 Haha! I approve. That's a nice prank, making someone's workstation moo at them. I've never worked (or had at school) an environment where I wasn't the only one on a unix machine, so I haven't had that opportunity. Windows is just so prevalent on Desktops...

About This Instructable

64,880views

16favorites

Bio: Hi, I'm psymansays. I'm an engineer from California. I enjoy sunsets, and long robot test drives on the beach. More from me: http ...
More by psymansays:Patio Garden Wicking Bed From 55 Gallon Steel DrumThe Bare Minimum DIY LatheBrowser based teleoperation for the LaptopWheels project
Add instructable to: