This blog is intended for people who wanted to install GUI or desktop environment on linux servers running on cloud and connect.
We are going to use VNC (Virtual Network Computing) protocol for accessing our remote desktop server.
What is VNC ?
Virtual network computing, or VNC, is a graphical desktop sharing system that allows you to control one computer remotely from another. A VNC server transfers keyboard and mouse events, and displays the remote host’s screen via a network connection, which allows you to operate a full desktop environment.
Basically ubuntu server and ubuntu cloud editions does not contains GUI, which needs to be installed before installing VNC server. Please note that server and cloud editions are carefully designed to utilize less hardware resources ( minimal environment ), installing GUI might leads to high hardware utilization.
Why I needed desktop environment in remote server ?
Just to explain a use case, let me tell me you how I ended up using VNC in first place. I was working on a problem which relates with cloud latency testing. My Friend, Neeraj (whose work revolves around core JS research & development) developed a javascript code that makes an cross origin HTTP API call to a loadbalancer near to the geographical location of browser and response will be delivered from loadbalancer in geographic proximity. To test this setup, executing JS code and to use developer console to see what's happening under the network layer, we were in need of a browser engine in different geographical location. I could have used some online paid or free service to get browser rented, services like browserstack or other alternatives but that has free minutes based trial restrictions.
Install a Desktop and VNC Server on Ubtunu 14.04
Step 1 - Install Ubuntu desktop
Start installing below gnome packages which helps VNC to load properly . These packages are required for all editions including ubuntu desktop .
$ sudo apt-get install --no-install-recommends ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal gnome-core
Step 2 - Install vnc4server package.
$ sudo apt-get install vnc4server
Step 3 - Make configuration changes in vncserver
Open /usr/bin/vncserver
file and edit as follows . Before editing, make a backup copy.
$ sudo cp /usr/bin/vncserver /usr/bin/vncserver.bkp
$ sudo vim /usr/bin/vncserver
#Find this line "# exec /etc/X11/xinit/xinitrcnn".
#and add these lines like below
"# exec /etc/X11/xinit/xinitrcnn".
"gnome-panel &n".
"gnome-settings-daemon &n".
"metacity &n".
"nautilus &n".
"gnome-terminal &n".
Step 4 - Start your vncserver
Now type the command vncserver
to start VNC session. you will be prompted for creating new vnc password.
$ vncserver
You will require a password to access your desktops through VNC Clients.
Password:******
Verify:******
xauth: file /root/.Xauthority does not exist
New 'ubuntu-desktop:1 (root)' desktop is ubuntu-desktop:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/ubuntu-desktop:1.log
Step 5 - To check VNC server has started, follow
$ netstat -tulpn
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 28372/Xvnc4
tcp6 0 0 :::5901 :::* LISTEN 28372/Xvnc4
VNC server is running and listening on 5901 port. Make sure your firewall allows inbound TCP connection to this port.
Step 6 - Configure your Firewall
If firewall is active, you need to open ports for inbound communication. If no firewall is enabled, you can skip this section.
#allow SSH
$ sudo ufw allow OpenSSH
#allowing single port 5901 port
$ sudo ufw allow 5901/tcp
#To allow series of port 5901 - 5910, follow
$ sudo ufw allow 5901:5910/tcp
#To check firewall rules
$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22/tcp (OpenSSH) ALLOW IN Anywhere
5901:5910/tcp ALLOW IN Anywhere
22/tcp (OpenSSH (v6)) ALLOW IN Anywhere (v6)
5901:5910/tcp (v6) ALLOW IN Anywhere (v6)WW
Step 7 - Connect to VNC Server
Use any remote desktop connect client that allow VNC protocol. Use IP address of server along with port where VNC server is listening.
Once connected to your VNC server, you will see screen of remote server where you installed desktop GUI.
Browser screen running on remote server.
That’s it, your VNC server is working.
Here I created my linux server in london, UK. I opened firefox through terminal to reach out to URL google.com. It opened google.co.uk domain based on regional search engine. You can do lot of other stuffs on VNC protocol to get things done from remote location.