Graphical user interface (GUI) for Google Compute Engine instance
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
Then we need to install the Gnome components for our virtual desktop. So type the following command:
$ 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 :) .
Install a Virtual Desktop using VNC
Now we need a VNC server to interact with desktop environment. I am using vnc4server, you can install your favorite one:
$ sudo apt-get install vnc4server
Start the vnc server, You’ll then be prompted to create and verify a new password:
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
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" &
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
First step is to tag our instance as a vnc-server, for that go to the VM description page and click on “add tags”
In order to communicate with our instance we need its external IP. You can find it on the Developers Console.
Let’s try to connect to it using netcat again:
$ nc 184.108.40.206 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.
Choose a descriptive name for the rule.
We will allow traffic coming from any source, which is why we use 0.0.0.0/0, 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
First, start the vncserver again on the VM by:
Now make sure that the connection is now allowed by the firewall:
$ nc 220.127.116.11 5901
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 18.104.22.168 22
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 email@example.com -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.
And boom!! Your Desktop environment is working. You can use Firefox browser for internet.
The Synaptic Package Manager
the Synaptic Package Manager does not get installed by default when you install the core gnome desktop. The Synaptic Package Manager is a great tool which makes adding and removing applications a breeze. You can install with this command:
$ sudo apt-get install synaptic
Note: VNCserver doesnot auto start on boot, you have to start it manually everytime you start the VM instance.