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
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:
-Xis the magic switch that turns on X11 forwarding
-Cactivates compression, which usually speeds up GUI interactions
-c blowfishswitches 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
wget the URL or you can just launch Firefox and browse normally:
You get the idea.
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.
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
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.
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.
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. :^)
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
thanks for your post! It helps me a lot~