Amazon EC2 remote desktop

By default, EC2 Linux AMIs tend not to come with a GUI like Gnome or KDE. Mostly EC2 instances are production servers and it makes sense there’s no GUI. But in development it’s handy to be able to edit code in an IDE like Komodo or Eclipse on the server rather than rely on remote debugging.

Setting up a windowed environment is possible and not that difficult. I’m using Ubuntu 10.04 (Lucid) so these comment apply to this environment (and probably to Debian too). For the rest your mileage will vary.

Update: See problem/resolutions at the end…

There are two parts: install the GUI; install remote desktop support.


This is straight forward. Begin by updating the Linux installation:

sudo apt-get update

Next install the desktop environment

sudo apt-get install ubuntu-desktop

Remote desktop

After installing the desktop environment there is still no desktop so it’s necessary to make the desktop available via a remote session. I’ll start by installing and using VNC so desktop can be started. But the VNC server is not very efficent so it’s better to use the ‘nx’ products from NoMachine which is an extra step. It’s also a little more complicated because NX uses SSH (which is good) but it’s installation requires more steps.


These two command install VNC and start it.

sudo apt-get install vnc4server<br />
vncserver :1

The second command runs a basic VNC server which is good enough. You will be prompted to enter a password.

The :1 is an instruction to create a window window which will be available on port 5901.

Go grab TightVNC for your client machine, install it and run it.

When TightVNC vnc starts you will be prompted for the password you entered when the VNC server was started. When the Tight VNC client connects you will be presented with a terminal window in the desktop type the following command to start your gnome desktop:

nohup gnome-session &

Wait a moment and the Gnome desktop will be available!


Here are instructions to setup NXServer. These instructions worked for me though it was essential that I:

Created a new user account and password

Run the nxserver –usercheck command to configure the user for SSH access.

I have found the NX remote desktop to be much faster than VNC.

You need to know that if you stop/reboot your EC2 instance the nxserver process will stop (unless you have set it to start on boot). If the nxserver is not started when your machine boots you will need to run these commands:

sudo /etc/init.d/ssh restart<br />
sudo /etc/init.d/nxserver restart

When you connect it takes a moment for the screen to be displayed. Be patient.

Problems and resolutions

Can’t connect after creating a new instance from an AMI

The cached keys are no longer valid so you need to delete the /usr/NX/home/nx/.ssh/known_hosts file.

Can’t connect after restarting an stopped instance

If told to look in /var/logs/messages and see ‘bad display name’ this means the display name (for example as it appears in the log or at the bash prompt) needs to be added to the hosts file resolving to

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.

Other Posts

Reader Comments

Hi, does this work with Amazon Linux AMI? I have read that remote desktop access is possible with Ubuntu and Red Hat on ec2. But couldn’t find any solution for Amazon Linux AMI.

I don’t know. If there is a Gnome or KDE package for the Amazon Linux AMIs it should work. If you are concerned, why use an Amazon Linux AMI? Why not use one of the other Linux AMIs? I have found the Bitnami AMIs pretty good. They have lots of pre-built AMIs based on Ubuntu.