Running X windows programs remotely on Windows

There are a few products out there for running X windows programs remotely on Windows, but you might be surprised to hear that the best one also happens to be free. I've used X-Win32 and Exceed in the past, both of which cost money, and neither of those products have worked as well for me as Cygwin.

Cygwin is actually a whole Linux-like environment that runs on Windows, but I don't make use of anything except its X windows support. After all, why use a fake Linux environment when you can run programs remotely on a real Linux machine? The whole beauty of X windows is that programs run remotely just about as well as they do locally.

Here's what you need to do to get Cygwin's X support working:

1. First of all, I'll assume you're using Putty as your SSH client.  It's a good free one, but other SSH clients will work, too.

2. Run the Cygwin installer and accept the defaults until you see the following screen:

Cygwin installer

3. Click the X11 line until it says 'Install' and then finish the installation.

4. Go to the newly created Cygwin start menu group and run Cygwin Bash Shell. After the command prompt starts up, type 'exit' to close the window.

IMPORTANT: Even though you may never want to use Cygwin's Linux-like environment, you MUST start it up at least once before trying to use X. Skipping this step will leave Cygwin stuck in an unusable state - trust me.

5. Cygwin comes with a handy batch file called 'startxwin.bat' for starting the X server. By default, it also opens a terminal window to the Cygwin environment. Since you won't be using that terminal window, you can prevent it from opening by adding REM before the following line near the bottom of startwin.bat (located here on my system C:\cygwin\usr\X11R6\bin):

%RUN% xterm -e /usr/bin/bash -l

6. Now make a shortcut to startwin.bat if you want and run it. You should see an X in the system tray at this point.

7. The only thing left to do is enable X11 forwarding in Putty as show below.  Keep in mind that this is not a global setting, so you'll need to make this change (and save it) for each saved session.

X11 forwarding in Putty

8. Now connect to your linux system and run 'xclock &' to see if it works.

xclock on Windows

9. That's it!