Graphical user interface (GUI) for Google Compute Engine instance

Aditya Choudhary
Mar 25, 2016 · 5 min read
Image for post
Image for post

Want to have GUI on your Google Compute Engine instance or use Internet browser on it? Here are the steps to install minimum required UI on Ubuntu 14.04 LTS VM(virtual machine) with Firefox . So let’s start.

Note: I am assuming that you have already created a VM instance with Ubuntu 14.04-LTS image and successfully running it.

Connect to your instance either through SSH option or use gcloud option. Once connected update the source list.

$ sudo apt-get update

Install the Gnome components

$ sudo apt-get install gnome-core

when prompted type Y and then press [Enter]. This will install the basic gnome desktop components. Normally gnome takes time but on GCE instance it flies :) .

If you prefer a lighter and faster alternative like Xfce, refer to this post.

Install a Virtual Desktop using VNC

$ sudo apt-get install vnc4server

Start the vnc server, You’ll then be prompted to create and verify a new password:

$ vncserver

Note: this password will grant access to your instance, so make it strong.

If everything went fine your VNC server is now running and listening on port 5901. You can verify this with netcat from the Google Compute Engine instance:

$ nc localhost 5901
RFB 003.008

We now need to kill the session we just created and make a tweak to the startup script for VNCServer to make it work properly. If we don’t perform this step then all we will see is a grey cross-hatched screen with an “X” cursor and/or a grey screen with a Terminal Session, depending on the Ubuntu version. Not very useful!

So, type the following command to kill the session:

$ vncserver -kill :1

Now open the file we need to edit:

$ vim .vnc/xstartup

Important: The modifications we need to make to this file depend on the version of Ubuntu we’re using so make sure you are using Ubuntu 14.04 LTS

Press the [Insert] key (“i” in Ubuntu) once (this will switch us into “edit” mode) and then edit the script so it ends up looking like this:


# Uncomment the following two lines for normal desktop:
# exec /etc/X11/xinit/xinitrc

#[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
#[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#vncconfig -iconic &
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &

metacity &
gnome-settings-daemon &
gnome-panel &

So, we’ve unmasked the unset SESSION_MANAGER line and masked out all the rest. We’ve then added the last 3 lines.When you’re done editing the .vnc/xstartup file for your particular version of Ubuntu press the [Esc] key once and type the following to save the changes and bring you back to the command line:


Installing a VNC client

Open the firewall

Image for post
Image for post
Add Tag to VM

In order to communicate with our instance we need its external IP. You can find it on the Developers Console.

Image for post
Image for post
Your External IP should look like this.

Let’s try to connect to it using netcat again:

$ nc 5901

The connection will fail, this is expected as the firewall rules block all communications by default for security reasons.
Let’s fix that.

Navigate to the configuration for the default network “Compute > Compute Engine > Network” and then click on default. Or you could also click hereand choose your project.

We’re going to add a new firewall rule, pressing the corresponding button.

Image for post
Image for post

Choose a descriptive name for the rule.

We will allow traffic coming from any source, which is why we use, the IP mask equivalent to a wildcard.

The traffic will be on the port 5901 for protocol TCP and going to instances tagged as vnc-server.

Connecting to the VNC server

$ vncserver

Now make sure that the connection is now allowed by the firewall:

$ nc 5901
RFB 003.008

Excellent! everything seems to be ready!!

If you still can’t connect but have followed steps correctly, there may be a issue of firewall blocking by your internet provider. Check the connection to port 22(SSH port).

$ nc 22
SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6

This can be resolved by ssh tunneling. Tutorials are available on google search :). Here is an example of tunneling command I used in my college where 5901 port is blocked. After this connect on localhost:5903 in the VNC Viewer.

$ ssh webmasteradi@ -L 5903:localhost:5901

Open your VNC viewer and connect to the IP of your Compute Engine instance on port 5901 or connect on localhost:5903(for ssh tunneling). To connect you’ll need to provide the password you gave at the beginning of this tutorial.

Image for post
Image for post
Connect to VM on port 5901

And boom!! Your Desktop environment is working. You can use Firefox browser for internet.

Image for post
Image for post
Minimal Gnome Desktop
Image for post
Image for post
Firefox on Google Compute Engine instance Ubuntu 14.04

The Synaptic Package Manager

$ sudo apt-get install synaptic

Note: VNCserver doesnot auto start on boot, you have to start it manually everytime you start the VM instance.

References :-

Your desktop on Google Cloud Platform

Administer Ubuntu Server Trusty Tahr 14.04LTS using VNC

Google Cloud - Community

Google Cloud community articles and blogs

Aditya Choudhary

Written by

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Aditya Choudhary

Written by

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store