VNCserver setup on Ubuntu

The Free TightVNC server works with Ubuntu and other modern Linux distros. In general the default 3-D Ubuntu desktop is not available over VNC, so we use a traditional 2-D desktop environment over VNC.

Install Linux VNC Server:

apt install tightvncserver openbox

Choose desktop environment on server PC: XFCE4, Openbox or other you prefer. Pick ONE of the following:


Install XFCE on server PC

apt install xfce4
apt remove xscreensaver xscreensaver-data

Create ~/.vnc/xstartup

#!/bin/sh
unset SESSION_MANAGER
startxfce4 &

Correct possible keystroke issues on server PC:

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

Openbox is the lightest-weight desktop environment–right click to open a menu. Otherwise, you just have a plain gray background, extremely minimal–good for embedded systems and old PCs.

Put into file ~/.vnc/xstartup

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

Start VNC server

vncserver :1 -geometry 1200x700 -localhost

Create a file ~/startVNC.sh containing:

#!/bin/sh
vncserver :1 -geometry 1200x700 -localhost

and then from my server username

crontab -e

adding the line:

@reboot  /home/username/startVNC.sh

If you have an encrypted /home drive, VNC and SSH require configuration to allow decrypting home drive upon SSH login.

Setup VNC client

On your laptop, install VNC client

apt install tigervnc-viewer

Alternatively:

apt install vncviewer

Create a shell script:

#!/usr/bin/env bash
ssh -f -L 5901:localhost:5901 user@IPaddress sleep 1;
vncviewer  localhost::5901

Notes

Openbox-Message: Unable to find a valid menu file “/var/lib/openbox/debian-menu.xml”

Wwhen I get this error, I’m also unable to open a terminal.

  • You can leave your VNC desktop running – it is not the same as your local desktop.
  • It is a little tricky to share your local desktop reliably. X11VNC can be more trouble than it is worth. It’s MUCH easier to startup a new separate desktop session with vncserver or x11vnc
  • After installing a new desktop environment, at your next local login, you’ll need to rechoose the traditional Ubuntu desktop (it will then remember this choice).

Security

Be sure that ports 5900-5999 are NOT exposed to outside world–VNC is NOT secure by itself! VNC must be tunneled over the Internet with SSH.

Ports exposed by the PC to the network are listed by:

ufw status

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


Kill a frozen/undesired desktop by logout of VNC from your laptop, then:

vncserver -kill :1

Fix non-working right-click Openbox menu by creating ~/.config/openbox/menu.xml with the content

<?xml version="1.0" encoding="utf-8"?>
<openbox_menu xmlns="https://openbox.org/" xmlns:xsi="https://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 menu icons under: Settings → Appearance. Set: Style-Xfce, Icons-ubuntu-mono-light, Fonts-turn hinting on if you want