Tools of the Trade

What's in a good programmer's tool belt?

11

JUL
2009

Load an EC2 GUI on Your Mac OS X Box

Using straight shell access on EC2 servers works just fine, of course, but there are images available that include the full desktop environment. If you use one of those, you can activate GUI programs on the EC2 server. Now you can't plug a monitor into your EC2 instance, so you will need to tunnel the GUI bits down to your local box. Luckily, Unix pretty much just handles all of this for you and if you can SSH into an EC2 instance and you have Apple's X11 installed, you are all set to try this.

I know at one time Apple's X11 environment was an optional install. I can't remember if it still is, but you can see if you have it by looking for a program called X11 in /Applications/Utilities/. Or, just fire up a Terminal and enter the command xterm. If a rather plain white shell window eventually appears, you are in business. If you do need to add the optional install, it should be on the disk that came with your computer (or the OS install disks).

Once you've confirmed X11 is ready, you need to fire up an EC2 instance. Create a Key Pair and configure a Security Group to at least allow SSH access. Then just launch an EC2 instance (I use the AWS Managment Console for that) with the needed desktop environment tools. I chose one of the wonderful Ubuntu Images by Eric Hammond.

Once the instance is running you are past all the hard parts! All that's left is to connect to the instance, with a few more options than you probably use normally. Here's the full command:

ssh -X -C -c blowfish -i KEY_FILE_PATH -l root INSTANCE_PUBLIC_DNS

Replace KEY_FILE_PATH with the path to the .pem file Amazon had you download while creating your Key Pair. Also replace INSTANCE_PUBLIC_DNS with the address listed as Public DNS in the AWS Management Console for the instance you launched.

Just FYI, here are the meanings of all the switches I used:

  • -X is the magic switch that turns on X11 forwarding
  • -C activates compression, which usually speeds up GUI interactions
  • -c blowfish switches to a faster encryption method, for even more speed
  • -i … allows you to specify your identity file
  • -l … allows you to specify your login (which a lot of people prefer to add to the front of the server address with an @ between the two)

When you're done playing around and plan to use an instance long term, I recommend creating a user, switching your -l username to that identity, and uploading your standard public key so you can drop the -i switch altogether. That's all work though and we're just trying things out here.

Enough setup, let's get to playing! Want to browse the instance files using a GUI browser? This command will launch Nautilis:

nautilus --no-desktop --browser

Need to download something to the instance? You could curl or wget the URL or you can just launch Firefox and browse normally:

firefox-3.0

You get the idea.

Notes

Avoid the Mac conventions of going after a Quit command in the menus. That will shutdown all of X11 and not just the current program. Instead, close the window of the program you wish to stop and your SSH session should give your prompt back.

I also seem to need to kill my SSH session (with a control-C) after I've been using GUI applications, even though I logout normally. I'm not sure why that is.

Comments (5)
  1. Charles L
    Charles L July 12th, 2009 Reply Link

    The reason for the Ctrl+C is because logging-out ends the terminal session but not any forwarding. This also occurs if you use any of the other port forwarding options (eg -D, -L or -R).

    Also, seeing as you're using Eric's builds, you should give the mac NX client a go - should be faster than plain X forwarding, and you can easily get a full session.

    1. Reply (using GitHub Flavored Markdown)

      Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

      Ajax loader
  2. Bennington Purcell
    Bennington Purcell September 7th, 2009 Reply Link

    This is great. I wonder why we aren't all renting our computer power directly at this point. You could build a little netbox just to run the GUI and have as much power as you wanted to pay for. And then have it just turn on and off the instance as you went. I was just loading up GIMP inside a instance and it worked great. Very cool.

    Note: i have a really fast connection so it makes it a little smoother than the average users experience would be.

    1. Reply (using GitHub Flavored Markdown)

      Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

      Ajax loader
  3. Karl
    Karl November 6th, 2009 Reply Link

    I was following along, but couldn't seem to get my DISPLAY environment variable to set on the EC2 instance having SSH'd as above... after some head banging, it turns out that it helps (a lot!) to yum groupinstall "X Window System" first, if your instance didn't already have X11. :^)

    1. Reply (using GitHub Flavored Markdown)

      Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

      Ajax loader
  4. Joe Moniz
    Joe Moniz June 17th, 2011 Reply Link

    Hey... Thanks for posting this. Clear, concise, and right to the point. That's a rare quality.

    Thank you again for taking the time to do this

    1. Reply (using GitHub Flavored Markdown)

      Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

      Ajax loader
  5. Joey
    Joey October 4th, 2012 Reply Link

    thanks for your post! It helps me a lot~

    1. Reply (using GitHub Flavored Markdown)

      Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

      Ajax loader
Leave a Comment (using GitHub Flavored Markdown)

Comments on this blog are moderated. Spam is removed, formatting is fixed, and there's a zero tolerance policy on intolerance.

Ajax loader