I have to work on a Windows machine at work every day. It’s okay, I suppose, but it’s Windows with all that implies. I’m more of a Linux person – I find that I am far more productive in a Linux environment simply due to a user interface that works the way I want to. Because of this I also spend much of my working day using Linux – even going so far as to sometimes shuffle files over the network to the Linux box so that I can work on them in that environment rather than in Windows. Whilst I may occasionally shuffle files around, though, I don’t really want to spend all day shuffling myself back and forth between two machines. So I just connect to the Linux box remotely, and work with all my normal Linux tools from my Windows machine.
There are several ways to remotely connect to a Linux box and I don’t profess that this approach is any better or worse than any other – it’s just the one that I happen to use, and that works well for me. Please note, however, that the method I use (XDMCP) uses an insecure protocol – whilst it’s fine to use it within an internal network with a good firewall between you and the internet at large, it’s not at all safe to use when your machines are directly connected to the internet, or where your network may not be secure (e.g. a typical wifi connection, or you just don’t trust your co-workers). Don’t say I didn’t warn you.
Step 1: Get yourself a Linux box
It goes without saying that you’ll need a Linux machine to connect to – but I’ll say it anyway. It doesn’t have to be a real Linux box – a virtual machine running in VMWare Player or Virtual Box will do (other virtualisation products are available). In any case you need to ensure that you’ve got a network connection between the Windows machine and the Linux box (the venerable “ping” command should suffice).
If you are setting up a Linux box from scratch – whether real or virtualised – then I recommend Ubuntu, at least in part because that’s what the rest of this post is based on.
Step 2: Enable Remote Login
• On the Ubuntu box log in with an administrator account and go to System=>Administration=>Login Window
• Go to the “Remote” tab and from the “Style” popup select something other than “Remote Login Disabled”. I use “Plain” to cut down on the amount of data going over the network and because it works better with the rootless option I’ll be using later. I also turn off the Logo option, again to keep things simple and plain
• Close the dialogue
(click on the image for a larger version)
• While you’re logged into the Linux box you need to find out its IP address. There are several ways to do this, but in Ubuntu you can get this from the System=>Administration=>Network Tools application. You’ll need to select your Network Device from the popup menu near the top of the “Devices” tab – for a physical machine it’s probably eth0 or eth1, but for a virtual machine you might need a bit of trial and error. Once you’ve got an IP you should be able to ping it from the Windows machine to confirm that it’s the right value
Finally you’ll need to restart GDM for the changes in the “Login Window” dialogue to take effect. Rebooting the Linux box will do the trick.
• Download a copy of Xming onto the Windows machine and install it
• Dig down in your Windows Start menu until you find the “Xming” option. Don’t launch it – you want to right click and select “Create Shortcut”. This will add an extra item to the menu, probably called “Xming (2)”
• Right-click on the new menu item and select “Properties”
• In the properties dialogue select the “General” tab and give the shortcut a more descriptive name. Then go to the “Shortcut” tab and edit the “Target” field to look something like this (all on one line, including the quotes – I’d copy and paste it if I were you):
"C:\Program Files\Xming\Xming.exe" :0 -clipboard -lesspointer -notrayicon -rootless -once -query 192.168.213.131
– The path should point to the real location of Xming.exe.
– Edit the IP after “-query” to be the IP of the Linux box you’re connecting to
• Apply the changes and close the Properties dialogue
Step 4: Your first remote connection
You should now be able to select the shortcut to launch Xming and connect to your Linux box. With luck you’ll be presented with a login screen, and should be able to log in.
If you don’t get a login screen then there’s clearly a problem. In my experience it’s likely to be one of two things:
1) The changes to enable remote login on the Linux box haven’t been applied properly. Check the settings in the dialogue, then reboot the machine to make sure that GDM gets restarted.
2) A firewall is blocking the connection. Temporarily disable any firewalls to see if that fixes the issue. If it does then you’ll need to open ports in your firewall to let the XDMCP connection through – but that’s outside the scope of this article (hint: at the least you’ll probably need to let UDP port 177 and TCP port 6000 through, search for “XDMCP firewall” or something similar for more details)
If you are having problems, make sure you quit any existing copy of Xming that may be running before trying again (right click on the taskbar entry and select “Close”). If you’re still having problems, bring up the task manager to ensure that there are no rogue XMing processes running which aren’t present on the task bar.
Step 5: Going rootless
If you’ve got this far then well done. You should now be able to log into your Linux box and use it as if you were sitting in front of it – with the exception of any fancy 3D or composited stuff (wobbly windows, spinning cubes, 3D games and so on) which unfortunately don’t work over a remote connection like this.
As you can see in the image above we’ve now got a full Linux desktop running, with the Windows taskbar at the bottom. Just above the Windows taskbar is the Ubuntu taskbar, showing the three Linux windows that are open. Conversely the Windows taskbar has just a single entry for Xming – all of the Linux windows live within a single “layer”. If you minimize Xming then all of the Linux windows go with it. Conversely if you bring Xming to the top of the window stack, all of the Linux windows come to the top as well.
For many people who just need a way to remotely access a Linux box, this will be good enough. But there are a some extra steps that you can take to make it a bit easier to switch between Linux and Windows.
• In Ubuntu press ALT-F2, type “gconf-editor” into the dialogue then press the RETURN key
• This should have launched Gnome’s registry-alike system
– Drill down to Apps=>Nautilus=>Preferences in the panel on the left
– Uncheck “show_desktop” in the panel on the right
– Close the window
• You should now find that your Linux desktop background has vanished. This is the result of using the “-rootless” parameter when launching Xming, and telling Nautilus not to draw the desktop via the gconf-editor setting in Linux. If you want the desktop back again, just re-check the option in gconf-editor.
In the screenshot above you can see the effect of disabling the Linux desktop – the Xming layer becomes transparent and your other Windows applications show through beneath your Linux windows. This means that you can easily bring a Windows application to the top of the window stack just by clicking on it. It also makes it easier to arrange your windows so that you can refer to the content of a Windows window whilst working in a Linux application.
The downside to this rootless approach is that you can no longer access any icons or mounted drives that appear on the Linux desktop. It’s not too bad, however, as the desktop folder is available from the “Places” menu, as are any mounted drives. For icons in particular you can always drag them to one of the Gnome panels if you want to have quick access to them.
On the subject of the Gnome panels it’s worth noting that they are highly customisable. With the default Ubuntu settings you’ll get two Gnome panels in addition to your Windows taskbar, but if this is too distracting you can remove one of the Gnome panels (or add others), move them around, or add various launchers and applications to them. A common option is to tweak it to a point where you have one Windows bar at the bottom of the screen, and one Linux bar at the top, making it easy to switch mental contexts between the two enviroments.
Step 6: Sharing a clipboard
Using the “-clipboard” parameter in XMing should allow the X-server’s clipboard (i.e. the Linux clipboard) to integrate with the Windows clipboard. Unfortunately this doesn’t work when you’re using GDM on the Linux end – i.e. the standard case for Gnome-based distros such as Ubuntu.
To fix this, edit the /etc/gdm/gdm.conf-custom file to include the following line just below the “[daemon]” line:
(you’ll need to edit this file as an administrator – press ALT-F2 then type “gksudo gedit /etc/gdm/gdm.conf-custom” into the box, without the quotes)
You’ll need to restart GDM for the change to take effect (e.g. reboot the machine), but thereafter you should have an integrated clipboard between the two environments. It only works for copying and pasting text, but it’s still pretty handy.
In case you’re not aware, Linux systems have two clipboards. There’s a Windows-style clipboard that you can use via menu entries or the usual CTRL-C/V/X keyboard shortcuts. But there’s also a “quick clipboard” – if you highlight some text, then middle-click somewhere else, the highlighted text gets inserted. This can be very useful when you get used to it, but does pose some problems for clipboard integration between Windows and Linux, so here are the basic rules:
• If you highlight some text in Linux you can then switch to the Windows environment and paste it using the menu option or CTRL-V
• If you copy/cut some text to the clipboard in Linux, using the menu option or CTRL-C/X, you can then switch to the Windows environment and paste it using the menu option or CTRL-V
• If you copy/cut some text to the clipboard in Windows, using the menu option or CTRL-C/X, you can switch to the Linux environment and paste it by middle-clicking with the mouse
• If you copy/cut some text to the clipboard in Windows, using the menu option or CTRL-C/X, you can switch to the Linux environment and paste it using the menu option or CTRL-V
• When pasting into Linux make sure that you don’t highlight any text first – if you do, that text will become the new clipboard contents, as per the first bullet point. In other words, you can’t highlight the text that you want to replace then paste the clipboard contents in because the clipboard contents will have been changed by the action of highlighting. If you want to replace some text, delete it first then do the copy and paste.
Extra bonus tips
In the instructions above, where you edit the properties for the shortcut, there’s a “:0” string. You can run more than one X server (i.e. more than one copy of Xming) on a single machine, by giving each one a separate screen number – “:1”, “:2″… (you’ll need to open ports 6001, 6002… on your firewall if you do this)
This lets you have more than one Linux desktop co-existing on your Windows desktop, which can be useful if you need to access multiple Linux machines for some reason. If you do this, then I recommend moving the taskbars to different locations and using different window themes for clarity – that makes it easier to keep track of which windows belong to which server.
You might want to consider putting SAMBA on the Linux box to allow your Windows machine to access files from it. Alternatively you could access a share on the Windows machine via the Ubuntu “Places” options (“Network” or “Connect to Server”), or by mounting the share with the SAMBA client tools. With the Gnome UI I’ve had most luck using the “Network” browser, then dragging my shared folder to the list of shortcuts on the left. Unfortunately not all applications like working with files that are accessed this way, but it is quick and convenient if you just want to be able to copy files between the two environments. Mounting a Windows share using the SAMBA client tools is a more widely supported means of accessing your Windows files from Linux, but requires more technical expertise to set up (see this page, for example).
Ubuntu has the ability to connect to an XDMCP server built-in. If you’ve enabled remote login on your Linux server as described above, then on another Ubuntu machine on your network press F10 at the login screen and select the XDMCP option. It will automatically scan for any XDMCP servers on your network and let you choose which one to use to log in.
You can even do this from the Live CD. Boot into it, then when the desktop comes up, log out (not shutdown) to get to the login screen, then press F10 as above. This can be very useful if you need to temporarily give people access to a Linux desktop but don’t want to install Xming on their Windows machines.
When you come to shut down the server you’ll find that there’s no option to do so via the XDMCP connection. You’ll need to shut down on the Linux server (or in the virtual environment) itself – use the “Options” (F10) menu on the Ubuntu login screen. Alternatively you can remotely log into the server’s command line using “ssh” and shutdown that way, if you know what you’re doing.