Novell Home

Xming - A X Server for Windows

Novell Cool Solutions: Tip
By David Mair

Digg This - Slashdot This

Posted: 22 Nov 2006
 

I try to look at freshmeat every day: http://freshmeat.net/. It's a site run by the Open Source Technology Group (OSTG). They also host sourceforge.net and a bunch of other sites you frequent. The freshmeat home page lists updates to open source projects as they are announced. With so many open source projects I find it pretty hard to keep track of the stuff I already use and am confident there are hundreds or thousands of gems I am unaware of but would like to use. By checking freshmeat regularly I find some of those gems and I've put many to use. I suppose, before getting into this cool solution I should point out that freshmeat itself is a cool solution.

Needless to say, none of you use Windows anyway but let's just pretend. So, there you are trawling through the latest marketing PowerPoint and wishing you could just die. Just as you are about to call the head of marketing to tell him his e-mail privileges have been revoked you get a call. Someone needs you to add a new user to their SLES10 box. Of course, you prefer the graphical YaST to the text one or to adduser (not that there's anything wrong with those). So, you start off that VNC session and rue the day you ordered the 56k line on a 10 year contract. Well, there is a better way.

If you've ever used a ssh session to locally run remote X applications on Linux then you probably thought it was very cool. Well, it only really depends on a listening X server on the local host and a ssh session that will tunnel X. You may not have noticed that PuTTY, my favourite Windows ssh client, can tunnel X. If you did notice it can then you might have wondered why. Well, you can tunnel it to any host on this side of the ssh session and there are some X servers for Windows. In the free world there's CygWin, then there are commercial X servers. I admit I don't really like CygWin. I like Linux the way it is but I like Windows the way it is too. Windows looking like Linux just doesn't thrill me.

Well, about a week before I wrote this I found a new version of Xming announced on freshmeat. It's a free X server for Windows and is a native Windows application and can render the output of X applications in several ways, including as free floating windows on your Windows desktop. IOW, X applications that have native Windows styling. The project site is here: http://www.straightrunning.com/

Why is Xming cool? Integration: you can run native X applications free floating on a Windows desktop and it's can be as secure as you can make ssh. The basic install is also small enough to fit on a thumb drive so you can carry a Windows X server in your pocket.

Installing Xming

Xming is a Windows application. At the time of writing, you can download the "Xming Microsoft Windows program installer" using the link in the Xming Packages section here: http://www.straightrunning.com/XmingNotes/ It's a normal Windows executable setup.exe. So, run it and follow the on-screen instructions.

You can also download the optional fonts installer (also a normal Windows executable setup.exe). It contains the X Windows standard fonts. The Xming server setup only has basic bitmap fonts sufficient for a minimal install. The fonts are a large download and aren't really necessary for normal use of Xming. If you are putting Xming on a thumb drive then don't bother with the fonts. If you are putting it on a host disk then why not. There's also a nice section in the page with the download links that gives you details on how to make your Windows fonts available to remote X applications displaying on your local desktop.

Most likely you will want to use ssh to connect to the remote host. I recommend PuTTY as a ssh client for Windows: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html You can add some convenience to Xming by also downloading Plink, Pageant and PuTTYgen. Each is a one file download of the Win32 binary executable. They are most useful if in the Windows path, I just put them in the Windows directory because I think they are generic (but very good) utilities. I don't propose to give a detailed discourse on using the PuTTY elements (maybe in another Cool Solution), I'll only refer to them in enough detail to support the use of Xming.

Starting Xming

When you look in the Windows Start Menu you'll find icons for Xming and XLaunch. XLaunch lets you select from the available configuration options and start the Xming server. I don't plan to describe it, since it is really just a launcher for the Xming server and I like the free floating native windows on my Windows desktop.

Verify that the Xming shortcut in the start menu uses the following arguments to the Xming.exe program:

:0 -clipboard -multiwindow

Note that the colon before the zero is intended. This enables the Xming server as screen zero, permits clipboard exchange between X and Windows applications and allows X applications to be free floating windows on the desktop. NB: The screen number really only defines the TCP port the X server will listen on. If the shortcut has these arguments then launch Xming via the shortcut. A X icon will appear in the system notification area (system tray) on the Windows desktop.

Using Xming

Using plink and pageant it is possible to automate the launching of remote applications but I'm going to start with manual launching of X applications via a shell command line.

Start PuTTY on the Windows host and you should see the PuTTY configuration dialog. You use this to setup the shell session you will connect on the Linux host.

In the Session category, type a hostname or IP address for the system you want to connect to (this is the host that will run the X applications).

If you are using a low bandwidth link then you can enable compression in the Connection->SSH category.

In the Connection->SSH->X11 category check the "Enable X11 forwarding" option and set the "X display location" to localhost:0 (if you used a screen number other than zero in the Xming.exe command line then use that number after the localhost:).

If you want to save this configuration to avoid having to repeat these steps every time you use it then switch back to the Session category, type a useful name in the "Saved Sessions" edit box and press the Save button.

Press the Open button to connect to the Linux host.

Enter an appropriate username and password.

At this point you should be at a shell prompt on the remote Linux system. If this was a shell session in a window on the X desktop of that system then you could run X applications by entering a command line and they would display on the X desktop you were running the shell in. Since you have Xming running on the Windows host and a ssh session with X forwarding enabled you can do the same thing. For example, start firefox at the shell prompt in PuTTY:

firefox

You should see the Linux version of Firefox start up right there on your Windows desktop. Prove it to yourself by trying to use the Tools->Options menu item to change the Firefox settings. That's right, it's Edit->Preferences on the Linux version! Note also that the Firefox window can be moved around on your Windows desktop and isn't contained by another window. It has a normal Windows title bar and buttons. Just for fun, start up the Windows version of Firefox as well and compare the two.

If you used the firefox command line as shown above then the shell session will be blocked waiting for Firefox to exit. Go ahead and close the running Linux Firefox. You can start a Linux program as a background process and continue to use the shell by adding an ampersand at the end of the command line:

firefox&

You should now see the Linux version of Firefox on your Windows desktop again but the shell prompt will still be waiting for input (you may have to press enter to see the input prompt but the shell is ready for input). Well, Firefox could be fooling us so let's try something more certain. If you are not logged into the shell as root then use su to become root then try this:

YaST2&

Yes, up comes YaST as a GUI application on your Windows desktop. You can go ahead and remotely manage your Linux host. Go ahead and run any other X application you know couldn't be faked on your Windows desktop.

What's really going on here

When you launched Firefox and YaST in the previous section your were running them on the remote Linux host. At no time were they running on your Windows desktop. Instead of displaying their output on the remote Linux system, they sent their window rendering commands through the X forwarding tunnel in PuTTY and to the Xming X server on the windows desktop and Xming executed those rendering commands in a Windows window. Because the program continues to run remotely you will be using and accessing resources on the remote computer. For example, YaST will be managing the Linux OS on the computer your shell session is connected to. Here's another fun example. If you closed YaST then restart it from the shell you currently have open:

YaST2&

Launch a new instance of PuTTY and create a session to a different SLES10 host, use the PuTTY configuration options described above. Login to the remote shell and start YaST2 on it:

YaST2&

You now have two YaST windows open on your Windows desktop. Use partitioner, the network configuration panel or something else to convince yourself each window is managing a different Linux host.

Streamlining the process

It quickly becomes inconvenient to start a PuTTY session and login to it just to be able to run X applications remotely. Fortunately, PuTTY and Xming integrate very well and you can automate the connection process so that all you appear to do is start remote applications by selecting them from menus on your Windows desktop.

If you right click on the Xming system tray icon you will see a default menu. You can extend this with your own options and they can start remote applications that display on your Windows desktop. There are several ways to do it and you can have nested menus.

The menu is controlled by a Xmingrc text file stored in your Windows profile directory C:\Documents and Settings\<username> in the case of a default Windows 2000/XP/2003 install. You can define your own menus by creating menu blocks:

menu mine {
	YaST exec "C:\Windows\plink -ssh -X -load srvr YaST2"
	Firefox exec "C:\Windows\plink -ssh -X -load srvr firefox"
}

This creates a menu containing two items, YaST and Firefox. Each executes a local command line that cause the relevant program to run remotely and display on the local system. You link this menu into the Xming context menu by adding it to an existing menu or making it the "root" menu:

menu mine {
	YaST exec "C:\Windows\plink -ssh -X -load srvr YaST2"
	Firefox exec "C:\Windows\plink -ssh -X -load srvr firefox"
}

menu other {
	Konsole exec "C:\Windows\plink -ssh -X -load srv2 /opt/kde3/bin/konsole"
}

menu top {
	"Server" menu mine
	"Server 2" menu other
}

RootMenu top

This creates two sub-menus, Server and Server 2. Each has its own list of programs that can be launched. You will need to shutdown and restart Xming for these changes to take effect.

You'll note that these command lines use plink rather than PuTTY. PuTTY is interactive and you'd have to select the connection and options, connect, login and run the target program (as you did in the examples above). Plink can do all of that automatically. The parameters are:

-ssh		Use ssh to connecting
-X		Enable X forwarding
-load srvr	Use the PuTTY saved session named srvr for connection settings

What follows those is the command line to execute on the remote system.

As shown, plink doesn't know the username and password. The username can be saved in a PuTTY session configuration but the password can't. You can use these plink options:

-l <username>
-pw <password>

I don't like these because they leave the password in the open in the Xmingrc file and I have very long passwords with spaces which the plink command line doesn't handle well. Instead, you can use PuTTYgen and pageant to create a public/private key pair for yourself and make the public key an authorised ssh key on the remote system. This will allow you to securely login to the remote host without a password.

Run PuTTYgen and press the Generate button. Wave the mouse around on the blank area to generate "randomness" for the key generation. Add a comment and I recommend adding a pass-phrase (a password for the key itself). Save the private key somewhere reasonably private, I create a putty directory under my Windows profile's Application Data directory and put the private key there. You can save the public key anywhere you want but I put it in the same directory as the private key.

The public key should also be shown in the PuTTYgen dialog box in a form suitable for OpenSSH authorized keys files. Highlight the text in that list box and copy it to the clipboard. Open a PuTTY session to a host you want to be able to login automatically to, login as the user they key is intended for. Use an editor to open the .ssh/authorized_keys file for the relevant user. Scroll to the bottom of the file. Paste the text from the Windows clipboard into the PuTTY session window and, if the editor is setup correctly, it will be added to the file. Save the file and exit from the editor. Using vi, for example:

  • Select the text in the PuTTYgen list box containing the OpenSSH ready public key
  • Copy it to the clipboard (Ctrl-C)
  • Start PuTTY
  • Select the configuration for the relevant remote host (or specify its IP address)
  • Open a session
  • Login as the user the key is intended for
  • vi ~/.ssh/authorized_keys
  • i
  • Right click in the PuTTY Window
  • :wq
  • exit

Load PuTTY again and select the session for the server you just put the public key on. Press the Load button. Select Connection->Data from the Category list. Enter the username used to save the public key above into the "auto-login username" edit box. Select the Connection->SSH->Auth category. Press the browse button in the private key option. Browse to the location of the private key saved from PuTTYgen and select it. Go back to the Session category and save the session.

At this point, if you open that session, you will be prompted for the generated key's passphrase, assuming you created one. That's still interactive. Pageant can be used to automate that. You can load private keys into it once and it will prompt for the passphrase once. Thereafter, if you use any PuTTY tool that uses the relevant public key then pageant will supply the private key automatically. You can supply a private key as a parameter on the pageant command line so you can create a Startup folder shortcut with a command line like:

pageant C:\Documents and Settings\<username>\Application Data\putty\my.ppk

When pageant starts you'll be prompted for your passphrase and, as long as you don't shutdown pageant the private key will be supplied to PuTTY applications running in your current Windows session as needed. So, if you now start PuTTY again and open the session saved with the public key and username you will see PuTTY connect and login without any intervention on your part. Plink will behave the same way and the sample command lines in the Xminrc menu items above should now start the specified applications without further interaction.

Final notes

I use programming editors a lot and fixed spacing fonts are very useful for alignment between lines. The fixed spacing fonts that are available with Xming are not the prettiest. I like some of the Windows True Type Fonts I have. The web page with all the information about Xming has a section on fonts: http://www.straightrunning.com/XmingNotes/fonts.htm If you download the Xming Tools and Clients installer as well you'll find some utilities that can be used to create X ready meta-data from your existing TTF files and they can then be used by remote applications displaying on your local desktop as if they were native X fonts. You'll need to add the directory containing the meta-data files and the TTF files as a -fp command line option when starting Xming.exe. That can create very long command lines that exceed the capabilities of Windows desktop shortcuts. You could add the command line to a batch file but you'd suffer the annoying display of a command prompt window to run it. That's where we will finally use Xlaunch. We won't actually use the program, we'll just hand generate a xlaunch data file and put it in the Start menu, Quick Launch bar or desktop as needed. The xlaunch files are simple XML files with command lines for Xming. Here's one that has everything I use for Xming, clipboard support, floating windows and my True Type Fonts:

<?xml version="1.0"?>
<XLaunch xmlns="http://www.straightrunning.com/XmingNotes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.straightrunning.com/XmingNotes XLaunch.xsd" WindowMode="MultiWindow"
ClientMode="NoClient" Display="0" Clipboard="true" ExtraParams="-fp "C:/Program
Files/Xming/fonts/misc/,C:/Program Files/Xming/fonts/TTF/,C:/Program
Files/Xming/fonts/Type1/,C:/Program Files/Xming/fonts/75dpi/,C:/Program
Files/Xming/fonts/100dpi/,C:/WINDOWS/Fonts/""/>

Note that the whole thing is on two lines in my xlaunch file. The second tag, the <XLaunch> one and the huge number of attributes are all on one line. The rendering on this page probably splits the line at whitespace, cut and paste accordingly. Save this as a xming.xlaunch file in the Start Menu, Desktop, Quick Launch bar or some other place on your Windows system. When you double click on it, the Xming X server will start with all of these parameters. It is probably best to save it somewhere other than the desktop, start menu or quick launch but create a shortcut to it in one of those locations. If you put that shortcut in the Startup folder in the start menu then the X server will launch when you login. If you have pageant launch at startup as well then you'll type your passphrase once at login then be able to run remote applications on your desktop as needed.

You can always start an interactive PuTTY session when you want to run something on a host you don't have a saved session for or public key on. Xming doesn't use the Windows registry or require configuration files other than in the Xming program directory. You can put PuTTY and the whole Xming directory on a thumb drive and have a portable X server for Windows.

Another note about fonts. The render size of some fonts on Windows is different from the render size on a Linux desktop. So, applications rendered by Xming may display with smaller or larger fonts than you expect. If you adjust the applications then be aware that you are adjusting the configuration on the remote host to fix a problem on the local display. So, be careful with the adjustments.

A few pictures

Here's a Windows desktop running Windows Paint and Microsoft's Visual Studio along with three open YaST windows: the root Yast window (mostly hidden); the package manager; and the network configuration window.


Click image for large view

Here's a picture of Windows and Linux firefox (note the menus), a KDE Konsole window and Windows GroupWise Messenger all displayed on a Windows desktop:


Click image for large view

Here's tcpdump running in Konsole while I use the GroupWise Client for Windows to tell the world about how cool it is. Tcpdump is showing the traffic for the session it is displaying over and it never dropped a packet. NB: the picture has been altered only to remove hostnames and e-mail addresses.


Click image for large view


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell