• Skip to main content
  • Skip to primary sidebar

Technical Notes Of
Ehi Kioya

Technical Notes Of Ehi Kioya

  • Forums
  • About
  • Contact
MENUMENU
  • Blog Home
  • AWS, Azure, Cloud
  • Backend (Server-Side)
  • Frontend (Client-Side)
  • SharePoint
  • Tools & Resources
    • CM/IN Ruler
    • URL Decoder
    • Text Hasher
    • Word Count
    • IP Lookup
  • Linux & Servers
  • Zero Code Tech
  • WordPress
  • Musings
  • More
    Categories
    • Cloud
    • Server-Side
    • Front-End
    • SharePoint
    • Tools
    • Linux
    • Zero Code
    • WordPress
    • Musings
Home » AWS, Azure, Cloud » VNC For Ubuntu On Amazon EC2 – A GUI To Your Server

VNC For Ubuntu On Amazon EC2 – A GUI To Your Server

By Ehi Kioya 16 Comments

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.

Some Terminology

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

Step 1:
Open up your AWS Management Console and on the EC2 tab, we need to create an Instance. Press the blue ‘Launch Instance’ button.

VNC For Ubuntu 1
Your screen might look a little different because I already have a running instance.

Step 2:
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.
VNC For Ubuntu 2

Step 3:
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.

Step 4:
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 ubuntu@75.101.166.76 where 75.101.166.76 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: ubuntu@ehikioya.com
    Note: If this method ubuntu@75.101.166.76 does not work, try entering the full public DNS value (you’ll get this from your AWS management console). Something like this: ubuntu@ec2-75.101.166.76.eu-west-1.compute.amazonaws.com
  • 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: 73.114.106.35: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.

Found this article valuable? Want to show your appreciation? Here are some options:

  1. Spread the word! Use these buttons to share this link on your favorite social media sites.
  2. Help me share this on . . .

    • Facebook
    • Twitter
    • LinkedIn
    • Reddit
    • Tumblr
    • Pinterest
    • Pocket
    • Telegram
    • WhatsApp
    • Skype
  3. Sign up to join my audience and receive email notifications when I publish new content.
  4. Contribute by adding a comment using the comments section below.
  5. Follow me on Twitter, LinkedIn, and Facebook.

Related

Filed Under: AWS, Azure, Cloud, Linux & Servers Tagged With: Amazon EC2, Ubuntu

About Ehi Kioya

I am a Toronto-based Software Engineer. I run this website as part hobby and part business.

To share your thoughts or get help with any of my posts, please drop a comment at the appropriate link.

You can contact me using the form on this page. I'm also on Twitter, LinkedIn, and Facebook.

Reader Interactions

Comments

  1. Rajagopal Subramanian says

    August 29, 2014 at 3:31 pm

    Dotted grey window is appeared. what will i do ? here is the window: https://docs.google.com/file/d/0BzK7h-AXtpjNbjU5NjlCN3ZObHM/edit

    Reply
    • Ehi Kioya says

      August 29, 2014 at 5:22 pm

      Hi Rajagopal,

      I have encountered that kind of dotted grey window before while working with an Amazon micro instance AMI.

      Looks like you server does not have enough power/resources to process the user interface. The problem may also be caused by bandwidth issues.

      Are you working with an EC2 micro instance?

      Reply
      • Rajagopal Subramanian says

        August 29, 2014 at 6:25 pm

        yes. My instance type is t2.micro. I use one-year free tier. Is there any way to get GUI ? pls..

        Reply
        • Rajagopal Subramanian says

          August 29, 2014 at 6:39 pm

          If i uncomment first line only, i can get terminal window. how’s that possible?

          Reply
          • Ehi Kioya says

            August 29, 2014 at 7:50 pm

            What did you uncomment? Did you find a fix? If so, please share with other users on here.

            Thanks.

        • Ehi Kioya says

          August 29, 2014 at 7:48 pm

          Sorry. But I think the t2.micro instance type might not have sufficient power to handle Virtual Network Computing. I had that issue before and the issue went away after I upgraded.

          One thing you can try though, is removing some of the unnecessary stuff you might have installed on the t2.micro server to free up some computing power.

          Let me know how that goes.

          Reply
          • Rajagopal Subramanian says

            August 30, 2014 at 1:56 am

            Thanks, But
            1)no i don’t find answer. If i uncomment first line only, i got terminal window
            #!/bin/sh
            # Uncomment the following two lines for normal desktop:
            unset SESSION_MANAGER
            #exec sh /etc/X11/xinit/xinitrc
            ….
            2)I only install ubuntu-desktop and vncserver in my server.

            3)same problem here: http://ubuntuforums.org/showthread.php?t=1707906 but i don’t how to change permission.
            when i first start vncserver after creating password, line like “xauth: file /home/ubuntu/.Xauthority does not exist” is shown

          • Ehi Kioya says

            August 30, 2014 at 9:51 am

            I doubt if the problem you’re having is with your xstartup configuration.

            Anyways, which file are you trying to change permissions for?

            Generally, if you locate the file you need to change permissions for you can just CHMOD it to 755. Or if you use an FTP client like WinSCP, you can easily manage file permissions from the WinSCP interface.

      • John says

        October 15, 2014 at 6:59 am

        Ehi, I’m also seeing the dotted gray window, but I’m running on a m3.medium instance. I’m also on ADSL 2+ so I doubt power or resources are the problem.

        Do you have any other ideas as what can be done?

        Reply
        • Ehi Kioya says

          October 15, 2014 at 7:49 am

          Hi John,

          Have you had a look here? Besides the resources issue I personally experienced, other users in the Ubuntu community seem to have managed to fix the issue by modifying permissions for a specific file.

          Let me know if your situation/error is similar to that described in the link above.

          Reply
          • John says

            October 16, 2014 at 5:11 am

            I have just changed the permissions of /etc/X11/xinit/xinitrc to 777 and it doesn’t seem to have made any difference.

          • falaktheoptimistFalak says

            November 19, 2015 at 5:18 am

            Chnaging the last line in .vnc/xstartup to
            gnome-session &

            and commenting out just the first line instead of both
            worked out for me to resolve grey screen error.

  2. Rajagopal Subramanian says

    August 30, 2014 at 11:19 am

    Thanks for ur continuous help. I see the vnc 1.log file

    ubuntu@ip-172-31-34-63:~/.vnc$ cat ip-172-31-34-63:1.log

    Xvnc Free Edition 4.1.1 – built Jan 14 2013 22:28:40
    Copyright (C) 2002-2005 RealVNC Ltd.
    See http://www.realvnc.com for information on VNC.
    Underlying X server release 40300000, The XFree86 Project, Inc

    Sat Aug 30 15:11:47 2014
    vncext: VNC extension running!
    vncext: Listening for VNC connections on port 5901
    vncext: created VNC server for screen 0

    error opening security policy file /etc/X11/xserver/SecurityPolicy
    Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/misc/, removing from l ist!
    Could not init font path element /usr/X11R6/lib/X11/fonts/75dpi/, removing from list!
    Could not init font path element /usr/X11R6/lib/X11/fonts/100dpi/, removing from list!
    Could not init font path element /usr/share/fonts/X11/75dpi/, removing from list !
    Could not init font path element /usr/share/fonts/X11/100dpi/, removing from lis t!

    Reply
    • Ehi Kioya says

      August 30, 2014 at 11:31 am

      Did you also see a line like this:

      1
      exec: 5: /etc/X11/xinit/xinitrc: Permission denied

      A user here was able to fix an error similar to yours by modifying permissions for that resource.

      If you don’t have that error though, then the most likely culprit, I think, would be insufficient system resources on your t2.micro instance.

      Reply
  3. Hastala says

    December 3, 2014 at 6:55 pm

    When trying to connect, TightVNC gave an error saying: “Could not connect because the target machine actively refused it”. What did I miss?

    Reply
    • Ehi Kioya says

      December 3, 2014 at 7:05 pm

      Your VNC server is probably not running. Make sure you first start the server by running vncserver command from the terminal. Then try to connect again.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

26,219
Followers
Follow
30,000
Connections
Connect
14,641
Page Fans
Like

POPULAR   FORUM   TOPICS

  • How to find the title of a song without knowing the lyrics
  • Welcome Message
  • How To Change Or Remove The WordPress Login Error Message
  • The Art of Exploratory Data Analysis (Part 1)
  • Getting Started with SQL: A Beginners Guide to Databases
  • Replacing The Default SQLite Database With PostgreSQL In Django
  • Understanding Routes In Laravel
  • Building A Blog With Laravel – Part 6: Creating A Form For New Posts
  • Getting Started With JupyterLab
  • How To Become A Self-taught Programmer
  • Recently   Popular   Posts   &   Pages
  • Actual Size Online Ruler Actual Size Online Ruler
    I created this page to measure your screen resolution and produce an online ruler of actual size. It's powered with JavaScript and HTML5.
  • Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library
    This article explains how to bypass the single user remote desktop connection restriction on Windows 10 by using the RDP wrapper library.
  • WordPress Password Hash Generator WordPress Password Hash Generator
    With this WordPress Password Hash Generator, you can convert a password to its hash, and then set a new password directly in the database.
  • Forums
  • About
  • Contact

© 2021   ·   Ehi Kioya   ·   All Rights Reserved
Privacy Policy