Setting Up VNC on Ubuntu in Amazon EC2

Tuesday May 1st 2012 by Eric Geier
Share:

While Amazon Elastic Compute Cloud offers only SSH access by default to Linux cloud servers, if you aren't a command-line fan or your application requires a GUI, discover how you can set up remote desktop access to most Linux cloud servers.

As with most cloud hosts, Amazon's Elastic Compute Cloud (Amazon EC2) offers only Secure Shell (SSH) access by default to Linux cloud servers. But if you aren't a command-line fan or your application requires a GUI, you can set up remote desktop access to most Linux cloud servers.

In this tutorial you'll discover exactly how to launch Ubuntu 10.04 LTS in Amazon EC2, install the desktop environment and configure a VNC (Virtual Networking Computing) server. In the end you'll have remote desktop access to Ubuntu, which will look and feel just like Ubuntu Desktop would on your PC.

Server TutorialsAmazon offers what they call the Free Usage Tier, basically a limited year-long trial of Amazon Web Services, including EC2, for new AWS customers. Thus you can set up and run Ubuntu as this tutorial discusses for no charge under the Free Usage Tier.

If you don't already have an Amazon Web Services account, you'll first need to create one. Next, go to the EC2 page on the AWS Management Console and ensure you're in the Region you desire (such as North California or Virginia) — perhaps the closest location to you and/or the users.

Starting the Ubuntu Instance

To get started, first click the Launch Instance button on the main EC2 page and then click Continue. Next, select the Ubuntu Server Cloud Guest version you prefer.

When configuring the instance settings, you can simply accept all the default settings or change them as you wish. You can change the Instance Type to increase the CPU and memory allocation for your virtual machine, but keep in mind the only Instance Type you can use under the Free Usage Tier is Micro (613 MB of memory).

When you get to the Instance Details page, consider enabling Termination Protection so you don't accidently terminate the instance, which would delete your virtual machine and any data on it.

If you haven't created a Key Pair yet for AWS (or for the particular Region you're deploying this instance in), it will prompt you to do so. Just keep the .pem file it downloads in a safe and secure location, as it's used to gain remote SSH access to your instance, and if you lose this file you may not be able to access the instance anymore.

Connecting to the Ubuntu Instance via SSH

In order to remotely connect to your instance via SSH you must first open up the SSH port in the firewall:

  • Go to the Security Groups page.

  • Select the Security Group your instance is assigned to (check on the Instances page if you're unsure).

  • Select the Inbound tab.

  • For Create a new rule, select SSH, click Add Rule and then Apply Rule Change.

Now you can connect to your instance via SSH. While you can use Amazon's Web-based SSH client, for increased functionality you should use a full-featured client like the free and open source PuTTY program for Windows and Unix platforms.

And when downloading PuTTY for Windows we recommend downloading the Windows installer package, so it's installed onto Windows like other programs and comes with the PuTTYgen program you'll also need.

Once you've installed PuTTY, run the PuTTYgen program and convert your private key .pem file into a PuTTY private key .ppk file:

  • Click the Load button, select the All Files option, select the .pem file you downloaded from Amazon EC2, and click Open.

  • Click OK on the prompt that appears.

  • For increased security you can create a password that you must enter when connecting via SSH with this private key. If desired, enter a password in the Key Passphrase and Confirm Passphrase fields.

  • Click the Save Private Key button, choose a safe and secure location, and click Save.

Now you can open the PuTTY program and configure it:

  • For the Host Name, enter your Public DNS address, which you can get from the AWS Instances page.
  • Then navigate to the Auth (authentication) settings: click Connection, SSH and Auth. Click the Browse button, select the .ppk file you generated with PuTTYgen and click Open.
  • So that you can later remote desktop into the instance, select Tunnels under the SSH settings. Enter 9000 for the Source Port and localhost:5901 for the Destination and then click Add.
  • Go back to the Session settings and you can save this configuration by entering a name in the textbox under Saved Sessions and clicking Save.

When you're ready to connect, click Open on the PuTTY program. Then log in as the ubuntu user. If you created a password when you generated your PuTTY private key, enter it; otherwise it should just connect.

Configuring Ubuntu with the Desktop Environment and VNC Server

Now you can install the desktop packages and remote desktop (VNC) server by entering (or copying and pasting) the following commands one at a time:

sudo apt-get update
sudo apt-get install ubuntu-desktop
sudo apt-get install vnc4server

 

Now, to configure the VNC server enter vncserver, which will then prompt you to create a password. Once created, enter vncserver -kill :1 to stop the server.

Next, configure the VNC xstartup file so you'll see the desktop when connecting via VNC. Enter vim .vnc/xstartup.

Then hit the Insert key, scroll around the text file with the keyboard arrows, and delete the pound (#) sign from the beginning of the two lines under the line that says "Uncomment the following two lines for normal desktop." And on the second line add "sh" so the line reads exec sh /etc/X11/xinit/xinitrc. When you're done, hit Ctrl + C on the keyboard, type :wq and hit Enter.

Now you can start the VNC server again by entering vncserver. And remember, you must enter this again at every reboot if you want VNC access, or consider configuring it to automatically run at startup.

Connecting to the Ubuntu Instance via VNC

Now that you have Ubuntu set up, you need to install a VNC client (like TightVNC) on your local machine, and when connecting enter the following address:

127.0.0.1:9000

When connecting via that address you must first connect to the server via SSH (like with PuTTY) and then connect with the VNC client.

If you prefer to connect directly to your Ubuntu instance via VNC rather than having to SSH into it first, you can use the Public DNS address (from the AWS Instances page of your instance) followed by a colon and the number one, such as ec2-184-169-226-14.us-west-1.compute.amazonaws.com:1.

Or you could even create an elastic IP and associate it with your Ubuntu instance, which you could then use (also with the colon and 1) to connect via VNC. But remember when connecting directly via VNC, it isn't as secure and you must open port 5901 up on the firewall via the Security Groups page.

Eric Geier is a freelance tech writer. He's also the founder of NoWiresSecurity, which provides a cloud-based Wi-Fi security service for businesses, and On Spot Techs, which provides on-site computer services.

Follow ServerWatch on Twitter

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved