How To: Remote Virtual Desktop

  • 1 min read

Today we're setting up a virtual desktop environment using a VNC server. This works for any provider such as DigitalOcean, AWS, Vultr, Hetzner, etc. pp.

Update & Install

Log in to your fresh Ubuntu machine via SSH, and type the following:

sudo apt update && sudo apt upgrade -y
sudo apt install tightvncserver xfce4 xfce4-goodies

Initialise VNC

To get to the password prompt we will initially run the server, set a password and kill it. This password has to be 6-8 characters long. Everything after the 8. character will be cut off.

vncserver
vncserver -kill :1

For changing it afterwards, simply run:

vncpasswd

Configure VNC

rm ~/.vnc/xstartup
vi ~/.vnc/xstartup

And add the following to xstartup:

#!/bin/sh
xrdb $HOME/.Xresources
startxfce4 &

And finally, make it executable and restart:

chmod +x ~/.vnc/xstartup
vncserver -depth 16 -geometry 1280x800

Connect To VNC

VNC doesn't a use secure connection, so always connect via a SSH tunnel to your desktop:

ssh -C -L 8888:127.0.0.1:5901 -N -l <vncserver_user> <vncserver_ip>

This command opens a secure tunnel from localhost:8888 to <vncserver_ip>:5901. Now open up your VNC client (e.g. Real VNC Viewer) and connect to localhost:8888.