So you want to access your Ubuntu Server like you would a regular desktop – with a graphical front end instead of just a terminal. This tutorial explains how you can do this using Virtual Network Computing (VNC). Since I’m a big fan of Amazon Web Services (AWS), I will be explaining how to set up VNC for Ubuntu on Amazon EC2. However, the general procedure described here will work for any normal Ubuntu server setup.
In the process of explaining how to set up VNC for Ubuntu, this tutorial will also give a general overview of how to get set up with an Amazon EC2 instance.
But What’s VNC?
VNC is a protocol that allows a desktop to be viewed and controlled remotely over the Internet. To use VNC, a VNC server must be run on the computer sharing the desktop, and a VNC client must be run on the computer that will access the shared desktop.
So Why Bother Setting Up VNC For Ubuntu?
Once you’ve installed Ubuntu Server you will need a mechanism to be able to administer it. One way is to install Putty. Putty gives you a “Command Line” interface and so you’ll need to learn a few Linux commands in order to be able to administer your server this way. Some people find this prospect rather too daunting and would prefer to use a graphical user interface (GUI) instead. As a result many people actually install Ubuntu Desktop instead of installing Ubuntu Server since the desktop version of Ubuntu has the GUI built in. There is a better way however, and that is to install VNC. VNC provides a “virtual desktop” so it is more lightweight than a full blown desktop installation.
Moreover, installing the desktop version will only make sense if you have physical access to your server. I’m assuming that most real web Servers for individuals and small businesses are remote or cloud hosted. Now, most cloud hosts (Amazon included) offer only Secure Shell (SSH) access by default to their Linux cloud Servers and SSH is terminal based by default.
Amazon Web Services (AWS) is a collection of remote computing services that together make up a cloud computing platform, offered over the Internet by Amazon.com. The most central and well-known of these services are Amazon EC2 and Amazon S3.
At the time of this writing, Amazon is still the biggest cloud provider. Newbies to cloud computing would definitely want to check out AWS.
Note: If this is your first time working with AWS, you might want to take advantage of the free tier. Here’s how it’s described on the AWS site:
To help new AWS customers get started in the cloud, AWS is introducing a free usage tier. The free tier can be used for anything you want to run in the cloud: launch new applications, test existing applications in the cloud, or simply gain hands-on experience with AWS.
With the free tier, you can play with an EC2 micro instance for a whole year for free! You also get a number of other services for free for one year depending on your interests. However, you will need a valid credit card to register.
Ok. Let’s skip the rant. Assuming you have signed up for Amazon Web Services, let’s learn how to launch an Ubuntu instance on Amazon EC2. Eventually, we will setup VNC for this instance.
Launching The Ubuntu EC2 Instance
Open up your AWS Management Console and on the EC2 tab, we need to create an Instance. Press the blue ‘Launch Instance’ button.
You will be presented with a large selection of Amazon Machine Images (AMIs) to choose from. I use Ubuntu Server 12.04 LTS. Check the “Free tier only” box to show only AMIs that are eligible for the free tier described earlier.
Your next option is to choose the Instance type you require. This is basically how much grunt you’re going to need. For a small blog site or if you are just testing stuff out, you should be okay with a micro instance, but for anything else you’ll need to choose something more powerful. A micro instance comes with 613MB of memory.
Most of the remaining instance details can be left default, but on the “Configure Instance” page, you might want to consider enabling Termination Protection so you don’t accidentally terminate the instance, which would delete your virtual machine and any data on it.
Next you need to create a key pair. This essentially works like a password to access your server. Just give it a name and click ‘Create and Download your Key Pair’, and save the generated .pem file in a safe place.
Note: If you lose this file you may not be able to access the instance anymore.
Now let’s set up SSH so we can connect to the Server.
Connect To The Ubuntu EC2 Instance Via SSH
By now, I assume you have already created and saved a key pair for your Ubuntu instance.
The last step in launching an EC2 Ubuntu instance is to create a security group, which is a set of firewall port rules. We will only deal with the SSH rules now because that’s all we need to remotely access our server and setup VNC.
Select the SSH protocol and enter the IP (or range of IPs) to allow. This will open up the SSH port in the firewall for the defined IP(s).
Complete the wizard by clicking “Review and Launch”.
Assign An Elastic IP To The Instance
By default, an EC2 instance is not assigned a public IP address. It is private. You can change this by creating an Elastic IP address (which is a public IP address that belongs to your AWS account) and associating this IP with your instance. This will make your EC2 instance accessible from the Internet.
Step 1: On the EC2 tab of your AWS console, press “Elastic IPs”
Step 2: Now press “Allocate New Address”
Step 3: You will be asked to select where you want to use the EIP. Select EC2 and press allocate
Step 4: Now select the newly created Elastic IP and press “Associate Address”
Step 5: Select your EC2 Instance from the list and press “Yes Associate”
Going forward, we can now access our EC2 instance with the IP address we just assigned.
Install PuTTY On Your Client Machine
Go to the PuTTY download page and download and install the Windows installer version of PuTTY. Please install everything in the package or at least make sure you install PuTTYgen.
Remember we created and saved a .pem file previously? Once you’ve installed PuTTY, run the PuTTYgen program and convert your private key .pem file into a PuTTY private key .ppk file. Here’s how:
- 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 open the PuTTY program and make the following configuration changes:
- For the Host Name, enter something like this email@example.com where 18.104.22.168 is the Elastic IP address you created and assigned to your instance. If you have already mapped your Elastic IP address to a domain name, you can simply enter the Host Name like this: firstname.lastname@example.org
Note: If this method email@example.com does not work, try entering the full public DNS value (you’ll get this from your AWS management console). Something like this: firstname.lastname@example.org
- In the Connection tab, select SSH then select Auth. Click the Browse button, select the .ppk file you generated with PuTTYgen and click Open
- 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 tab and you can save this configuration by entering a name in the textbox under Saved Sessions and clicking Save
Now you can connect to your Ubuntu Server via the PuTTY terminal, 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 just connect.
We’re almost there. Here’s how to set up VNC for the Ubuntu Server.
Install Ubuntu Desktop And VNC Server
Log in to your server using PuTTY as explained above.
Now, you will install the required packages to make VNC work. Run the following commands one by one:
sudo apt-get update sudo apt-get install ubuntu-desktop sudo apt-get install vnc4server
Now type vncserver
You will be prompted to create a password. Once created, type 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. You can also edit the file manually if you have FTP access.
Start the VNC server again by typing vncserver. Going forward, you must enter this again at every reboot if you want VNC access. If this bothers you, then consider configuring it to automatically run at startup. It’s just a cron thingy 🙂
Install The VNC Client
Download and Install TightVNC on your local machine. This will be our VNC client.
Make sure PuTTY is running and you’re logged in to your server via SSH.
Run TightVNC and in the Remote Host textbox, enter 127.0.0.1:9000
A graphical front end to your Ubuntu Server on Amazon EC2 will open!
If you don’t want to always have PuTTY running when you use TightVNC, you can also use the Elastic IP you created earlier. Instead of 127.0.0.1:9000, just enter your Elastic IP followed by :1
So it will be something like: 22.214.171.124:1
Or if you have already mapped your IP address to a domain name in DNS, it can simply be something like: ehikioya.com:1
Note though that when connecting directly via VNC, it isn’t as secure because you must open port 5901 up on the firewall via the Security Groups page on your EC2.