How To Install VNC Server on Ubuntu 14.04

Install VNC Server on Ubuntu 14.04

In this tutorial, we will show you how to install and configuration the VNC Server on Ubuntu 14.04. For those of you who didn’t know, VNC (Virtual Network Computing) server is a free and open-source software which is designed for allowing remote access to the Desktop Environment of the server to the VNC Client whereas  VNC viewer is used on the remote computer to connect to the server.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation VNC Server on an Ubuntu 14.04 server.

Install VNC Server on Ubuntu 14.04

Step 1. First, make sure that all your system packages are up-to-date by running the following apt-get commands in the terminal.

sudo apt-get update
sudo apt-get upgrade

Step 2. Installing a VNC Server on the Ubuntu system.

By default, most Linux server installations will not come with a graphical desktop environment. In this case, you need to install one that you can work with. In this example, we will install xfce4:

apt-get install gnome-core xfce4 firefox
apt-get install vnc4server

Step 3. Configure VNC Server.

First, add a new user called vncuser you can use any user as you want:

adduser idroot
passwd idroot

Now switch to the user you want to log in to the VNC server with. We are going to modify xstartup file to start xfce4 session whenever VNC server is started:

su - idroot
vncserver

VNC server will ask you for a password you want to use to log in to the VNC server. This is the sample output:

[email protected]:~$ vncserver
You will require a password to access your desktops.
Password:
Verify:
xauth:  file /home/vncuser/.Xauthority does not exist
New 'idroot:1 (vncuser)' desktop is idroot:1
Creating default startup script /home/vncuser/.vnc/xstartup
Starting applications specified in /home/vncuser/.vnc/xstartup
Log file is /home/vncuser/.vnc/idroot:1.log

After VNC Server started and created some of its files. We are now can turn it off to modify the xstartup file (startup script) to make it start with xfce4:

vncserver -kill :1

Before we begin configuring our new xstartup file, let’s back up the original in case we need it later:

cp ~/.vnc/xstartup ~/.vnc/xstartup.bak
> ~/.vnc/xstartup
nano ~/.vnc/xstartup

Add the following lines:

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &

The next step is to create a VNC Server startup script. You must do this with the root user:

su -
nano /etc/init.d/vncserver

Copy this configuration and save it into the file:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          tightvncserver
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: vnc server
#
### END INIT INFO
 
unset VNCSERVERARGS
VNCSERVERS=""
[ -f /etc/vncserver/vncservers.conf ] && . /etc/vncserver/vncservers.conf
prog=$"VNC server"
start() {
 . /lib/lsb/init-functions
 REQ_USER=$2
 echo -n $"Starting $prog: "
 ulimit -S -c 0 >/dev/null 2>&1
 RETVAL=0
 for display in ${VNCSERVERS}
 do
 export USER="${display##*:}"
 if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
 echo -n "${display} "
 unset BASH_ENV ENV
 DISP="${display%%:*}"
 export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
 su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"
 fi
 done
}
stop() {
 . /lib/lsb/init-functions
 REQ_USER=$2
 echo -n $"Shutting down VNCServer: "
 for display in ${VNCSERVERS}
 do
 export USER="${display##*:}"
 if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
 echo -n "${display} "
 unset BASH_ENV ENV
 export USER="${display##*:}"
 su ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
 fi
 done
 echo -e "\n"
 echo "VNCServer Stopped"
}
case "$1" in
start)
start [email protected]
;;
stop)
stop [email protected]
;;
restart|reload)
stop [email protected]
sleep 3
start [email protected]
;;
condrestart)
if [ -f /var/lock/subsys/vncserver ]; then
stop [email protected]
sleep 3
start [email protected]
fi
;;
status)
status Xvnc
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac

Make vnc server startup script executable:

chmod +x /etc/init.d/vncserver

Step 4. Accessing VNC.

To access the remote desktop on the VNC server from the windows system, you must have a VNC viewer installed on your system. There is various VNC viewer available to use. Download any one and install on your system, for example:

Install VNC Server on Ubuntu 14.04

Congratulations! You have successfully installed VNC Server. Thanks for using this tutorial for installing VNC Server on your Ubuntu 14.04 system. For additional help or useful information, we recommend you check the official VNC website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!