LinuxTutorialsUbuntu

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 free and open-source software that is designed for allowing remote access to the Desktop Environment of the server to the VNC Client whereas the 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 the step-by-step installation VNC Server on an Ubuntu 14.04 server.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 14.04, and any other Debian-based distribution.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

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 the 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:

root@server:~$ 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 $@
;;
stop)
stop $@
;;
restart|reload)
stop $@
sleep 3
start $@
;;
condrestart)
if [ -f /var/lock/subsys/vncserver ]; then
stop $@
sleep 3
start $@
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 anyone and install it 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!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button