vncserver setup on Ubuntu

Setup the Free TightVNC server on Ubuntu 12.04-17.04 and beyond. In general the 3-D Unity Ubuntu desktop is not available over VNC, so we use a traditional 2-D desktop environment XFCE.

0. Security

You must be sure that ports 5900-5999 are NOT exposed to outside world–VNC is NOT secure by itself! You must tunnel with SSH.

You can see which ports are exposed to outside world by typing:

sudo ufw status

You should see only port 22 and any other ports only if you know what they are for.

1. Install Linux VNC Server

sudo apt install tightvncserver xfce4 openbox

sudo apt remove xscreensaver  xscreensaver-data

mkdir ~/.vnc
touch ~/.vnc/xstartup
chmod +x ~/.vnc/xstartup

xfconf-query -c xfce4-keyboard-shortcuts -p /xfwm4/custom/'<'Super'>'Tab -r

2. Choose desktop environment

You can choose XFCE4 or Openbox (or other you prefer). Pick ONE of the following:

XFCE4

XFCE4 is a traditional Windows XP-like desktop environment by putting the following into ~/.vnc/xstartup

 #!/bin/sh
 unset SESSION_MANAGER
 startxfce4 &

Openbox

Openbox is the lightest-weight desktop environment–right click to open a menu. Otherwise, you just have a plain grey background, extremely minimal–good for embedded system and old PCs. If you want Openbox, put into ~/.vnc/xstartup

 #!/bin/sh
 unset SESSION_MANAGER
 exec openbox-session &

3. start/restart VNC server

e.g. after rebooting, or set a crontab task to do this at reboot:

 vncserver :1 -geometry 1200x700 -localhost

Kill a frozen/undesired desktop

logout of VNC from your laptop, then:

vncserver -kill :1

4. Connect from laptop

One time install on your laptop:

sudo apt install vncviewer

create a Bash script like:

#!/bin/bash
ssh -f -L 5901:localhost:5901 [email protected] sleep 1;
vncviewer  localhost::5901

Notes on VNC

You can leave your VNC desktop running – it is not the same as your local desktop. It is a little tricky to use your local desktop reliably–I have done so with X11VNC, but it can be more trouble than it is worth! It’s MUCH easier to startup a new separate desktop session with vncserver or x11vnc

reference xfconf fixing broken tab

Fix non-working right-click Openbox menu

You might need to create ~/.config/openbox/menu.xml with the content

<?xml version="1.0" encoding="utf-8"?>
<openbox_menu xmlns="http://openbox.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="/usr/share/openbox/menu.xsd">
    <menu id="root-menu" label="Openbox 3">
        <item label="Run Program">
            <action name="Execute">
                <execute>
                    gmrun
                </execute>
            </action>
        </item>
        <separator/>
        <item label="Terminal">
            <action name="Execute">
                <execute>
                    xterm
                </execute>
            </action>
        </item>
  </menu>
</openbox_menu>

Fix missing XFCE4 VNC icons

The default XFCE4 desktop may be missing menu icons (you see black squares or red X’s).

Settings > Appearance

  • Style: Xfce-4.6
  • Icons: ubuntu-mono-light
  • Fonts: turn hinting on if you want

Leave a Comment