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

by psymansays in Circuits > Microsoft

114140 Views, 18 Favorites, 0 Comments

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

screenshot-xeyes.png
 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.

Set Up Your SSH Client

Tunnelier-1.jpg
Tunnelier-2.jpg
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.

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.

Make Sure That OpenSSH Is Installed on Linux

Screenshot-Terminal-1.png
 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.

Add an Automatic "DISPLAY" Variable for the Linux Computer

Screenshot-Terminal-2.png
Screenshot-Terminal-3.png
Screenshot-Terminal-4.png
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.

Start Your SSH Client.

Tunnelier-1.jpg
screenshot-xeyes.png
 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!

Linux-to-Linux Version

Screenshot-SSH-LoopBack.png
Screenshot-SSH-LoopBack-Xeyes.png
 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.