How to install and configure a VNC server


VNC (Virtual Network Computing) is a remote access protocol that allows you to interact with windowing systems on various operating systems.

CloudShare recently added the ability to connect via VNC to a virtual machine, directly in your browser.  This guide looks at installing a VNC server on Ubuntu Server 14.04.  

For this tutorial you will need an Ubuntu server 14.04 machine, configured with a non-root user, and shell access, either via SSH or console.

(Apologies for the lack of true code snippets below, code will be in bold.)


Step One

First we will need to install a desktop environment, preferably a lightweight one that VNC will work best with. We will also install TightVNC and autocutsel. The former is our VNC server, and the latter will allow us to have a bidirectional clipboard.

sudo apt-get update

sudo apt-get install xubuntu-desktop tightvncserver autocutsel

Next we will run tightvncserver once and then shut it down, this will create the ~/.vnc directory that holds TightVNC's configuration. If this is the first time you run tightvncserver it will prompt you for a password, don't worry you can change it later on. Enter n if asked to enter a 'view-only' password:


tightvncserver -kill :1



Step Two

We will now configure our VNC server to start up a new display with the XFCE 4 desktop environment and autocutsel for clipboarding:

Backup the xstartup file:

cp ~/.vnc/xstartup ~/.vnc/xstartup.bak

Edit xstartup to look like this with your favorite editor

(like so nano ~/.vnc/xstartup):

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
autocutsel -fork
startxfce4 &

Make xstartup executable:
chmod +x ~/.vnc/xstartup

Choose a password, or change your current one if you want. Enter n if asked to enter a 'view-only' password:

You now already have your VNC server configured and ready for testing. To test your VNC server start it up:

Connect to the machine using CloudShare's HTML VNC client, or any native client. Use port 5901 and the password you gave the vncpasswd command or the first run of tightvncserver

Shut it down afterwards:
tightvncserver -kill :1


Step Three

We will now configure our machine to automatically start the VNC server on startup. Fire up nano (or any editor) as root and create a new file at /etc/init.d/vncserver :
sudo nano /etc/init.d/vncserver

Edit the file to look like this:

export USER="sysadmin"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions

case "$1" in

log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"


log_action_begin_msg "Stopping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"

$0 stop
$0 start


exit 0


Possible changes to make to the script above:

1. export USER="sysadmin"

  • Replace the sysadmin user to your non-root user.

2. GEOMETRY="1024x768"

  • Set the desktop resolution
  • 1024 is the width, and 768 is the height

3. DISPLAY="1" (You usually don't need to change that.)

  • Change which X Windows display number the VNC server take.
  • The DISPLAY variable will also affect which port the VNC server will listen on. For example, DISPLAY="1" will cause the server to listen on port 5901, DISPLAY="2" will cause the server to listen on port 5902 and so on


Make the file executable:
sudo chmod +x /etc/init.d/vncserver


Check that it works via the service command:

sudo service vncserver start

sudo service vncserver restart

sudo service vncserver stop


Register the service:

sudo update-rc.d vncserver defaults




You're all done!
Use the port and password of your VNC server with the client of your choosing.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk