I have shown you How to install VNC Server on CentOS 6, today I’m going to show you How to install VNC Server on Ubuntu 14.04 since many people like and use Ubuntu these days. I mostly spend time with Centos but not with Ubuntu. I spent quite sometimes to make VNC Server to work on Ubuntu 14.04 because gnome doesn’t play nice with VNC Server.
Update and Upgrade Ubuntu 14.04
To make sure the installation of VNC Server go smoothly, check your Ubuntu 14.04 is up to date.
$ su - <h1>apt-get update; apt-get dist-upgrade -y --force-yes</h1>
Install GUI on Ubuntu 14.04 Server
If you have Ubuntu 14.04 LTS (Trusty Tahr) Desktop version, you can skip gnome-core and xubuntu-desktop packages, you will only need xfce4. Well we don’t need a GUI on Ubuntu 14.04 over ssh, but for VNC purpose we are going to install a GUI to work with Ubuntu comfortably. There are two options here for you to choose, either gnome-core with xfce4, or xubuntu-desktop with xfce4. I have tried to make gnome to work over VNC but no luck so far. So make your pick.
# apt-get install gnome-core xfce4 firefox nano -y --force-yes
Or
# apt-get install xubuntu-desktop xfce4 firefox nano -y --force-yes
Install VNC Server on Ubuntu 14.04
It’s quite simple to install VNC server on Ubuntu 14.04, but it’s not that simple to configure VNC server 🙂
# apt-get install vnc4server -y --force-yes
Configure VNC Server to work on Ubuntu 14.04
You can remotely control your Ubuntu 14.04 system via VNC with any user that you want. Some people would recommend you to install and run login to VNC server as root user to avoid sudo escalation privileges which is not a good security practice at all. In this tutorial I will add new user called vncuser you can use any user as you want.
# adduser vncuser
set vncuser password
# passwd vncuser
Now switch to the user you want to login to VNC server with. We are going to modify xstartup file to start xfce4 session whenever VNC server is started.
# su - vncuser
Start VNC server with that user for VNC server to create some necessary files first time.
$ vncserver
VNC server will ask you for a password you want to use to login to VNC server, this password does not necessary to be the same as regular user password. This is the sample output
vncuser@namhuy:~$ vncserver You will require a password to access your desktops. Password: Verify: xauth: file /home/vncuser/.Xauthority does not exist New 'namhuy:1 (vncuser)' desktop is namhuy:1 Creating default startup script /home/vncuser/.vnc/xstartup Starting applications specified in /home/vncuser/.vnc/xstartup Log file is /home/vncuser/.vnc/namhuy:1.log
After VNC Server started and created some of it’s files. We are now can turn it off to modify the xstartup file (startup script) to make it start with xfce4 instead of gnome which doesn’t work right with VNC Server on Ubuntu 14.04.
To kill VNC Server session
$ vncserver -kill :1
To modify xstartup file (these commands will empty xstartup file, if you installed wine before vnc server and you want to keep the old content of xstartup file, skip this line $ > .vnc/xstartup ) thanks Hamid
$ cd ~ $ > .vnc/xstartup $ nano .vnc/xstartup
#!/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 &
$ su - <h1>nano /etc/init.d/vncserver</h1>
With the content
#!/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 # Description: http://www.namhuy.net # ### 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
# chmod +x /etc/init.d/vncserver
# mkdir -p /etc/vncserver <h1>nano /etc/vncserver/vncservers.conf</h1>
VNCSERVERS="1:vncuser" VNCSERVERARGS[1]="-geometry 1024x768"
# update-rc.d vncserver defaults 99
update-rc.d: warning: /etc/init.d/vncserver missing LSB information update-rc.d: see Adding system startup for /etc/init.d/vncserver ... /etc/rc0.d/K99vncserver -> ../init.d/vncserver /etc/rc1.d/K99vncserver -> ../init.d/vncserver /etc/rc6.d/K99vncserver -> ../init.d/vncserver /etc/rc2.d/S99vncserver -> ../init.d/vncserver /etc/rc3.d/S99vncserver -> ../init.d/vncserver /etc/rc4.d/S99vncserver -> ../init.d/vncserver /etc/rc5.d/S99vncserver -> ../init.d/vncserver
# reboot