Building a Linux server is a fairly simple affair. If you’re anything like me, you had some old hardware lying around which you shoved into a cheap case, stuck a copy of Debian/Ubuntu/Fedora/Whatever on it, and bob’s your uncle.
But once it’s up and running, should you dedicate a monitor/keyboard/mouse to a computer you barely use? Or is there another option?
Thankfully, one thing Linux has in spades is Options.
Today I’m going to deal with X11 forwarding over SSH. As you may know, SSH is one of the primary ways of connecting in to your Linux server, but it’s normally used for terminal commands – something some people aren’t all that comfortable with.
X11 forwarding over SSH allows the display of any programs you’d normally run from within a Gnome or KDE session to be displayed remotely, with only a few steps to make it possible.
First up, you’ll need an SSH client for your current machine. If you’re using Windows, the best option in my opinion is PuTTY, as it’s free and easy to use. On Mac, your SSH client comes built in, and is called ssh.
Next, we’ll need an X server. Windows-wise, there are a couple of options such as XWin32 (commercial software) and XMing (freeware). As I’m a cheapskate, I’m going with XMing. Again, Mac users have this preloaded providing you installed X11 when you installed OSX.
So, first step. Install PuTTY and fire it up. You should see a window like this:
The Host Name or IP Address field is the important one here. Enter the name or IP address of your Linux computer. Leave the port at 22 (unless you’ve changed the default SSH port), then click on SSH in the tree on the left hand side.
Turn on compression to speed up your connection, and bring Blowfish to the top of the list. Blowfish is still relatively secure, but will be a heck of a lot quicker than AES at passing information as your computer doesn’t have to encrypt things so heavily.
Next, click on X11, and turn on “enable X11 forwarding.” You can also modify the display number if you intend to have multiple machines displaying at once, but I usually leave it as default (display 0).
Finally, let’s go back to the session option at the top of the tree and save our session so we don’t have to type this stuff in every time. I’ll call this connection ‘mycomputer’ and press save down the bottom. Then it’ll appear in the bottom window next time I start PuTTY.
Ok, go ahead and click the Open button in the bottom right corner to connect to your machine. You’ll be greeted with a username/password prompt. Use your standard user login, though – as root logins over any remote connection are a serious no-no.
Good, so we’re now connected via SSH and X11 forwarding is enabled. But we can’t run anything just yet, as we don’t have a local X server to display the information we’re after.
So after installing XMing, I’m going to start it using XLaunch, which can be found in your start menu. There are essentially two main options for us to use. First, we can use multiple windows, which will allow us to run single programs within Windows, kind of like VMWare’s Unity functionality. We’ll try that one first.
The next screen gives us the option to start a client, which essentially we’ve already done with PuTTY. You can select another option, which will use an embedded version of PuTTY to connect to the remote machine transparently and fire off a command, but that’s a howto for another day. For now, we’ll leave it off.
Next up is some advanced stuff about font servers which we won’t worry about at this stage.
And finally the option to save your connection as and .xlaunch file should you want to run it again in the future. Save if you want to, then hit ‘finish’.
Once you do, it’ll disappear and you’ll notice a new X logo in your task tray. This means that the X server is now running and ready to accept commands. Go back to PuTTY and we’ll give it one. In PuTTY, I’ll type ‘firefox &’ – the ampersand breaks the process off and lets it run on its own so we can continue using the terminal.
Holy cow, Batman! Remote Firefox!
So running one program at a time is fine, but what happens if we want a full desktop? First thing we’ll do is close our current XMing session by exiting any open programs, right clicking on the X in the tasktray and selecting ‘exit.’ Then we’ll fire up XLaunch again to select a different X server layout.
I’m going to choose ‘single window,’ as I prefer to have remote sessions locked a way somewhat.
Hit next all the way through and press finish. You’ll be greeted with an ugly gray crosshatched window.
That’s what an X server looks like when it’s not rendering anything, so there’s no need to panic. But let’s put something up there to cover the blandness.
Back in PuTTY, type ‘gnome-session &’ if you’re a Gnome user, or ‘kde-session &’ if you’re a KDE person. It’ll send a command off to your other computer that it’s to launch your main desktop environment, and after a moment it’ll display like this.
So that’s the ins and outs of connecting to your Linux machine via a seamless X11 forwarded session.
Oh, if you’re a Mac user, I probably should tell you how things are done. It’s pretty difficult, so maybe you should all go grab your security blankey right away.
First, open up a terminal session by browsing to your applications folder, then the utilities folder, and clicking on Terminal.
Type the following command:
ssh your.server.ip.address -XC
The X enables X11 forwarding, and the C enables compression.
Once you log in, all you need to do is fire off some commands like ‘firefox &’ and you’re away. Easy, huh?
The last thing I’d like to note is that this option is also quite possible over a remote connection (say, from the office so your boss doesn’t know what you’re browsing). All you need to do is set up some port forwarding on your router and point port 22 at the IP address of your Linux server. Then from the office, fire up PuTTY and enter the public IP address of your internet connection.