09.02.2024

How to Install TightVNC Server on Ubuntu 20.04

In this tutorial, we will install TightVNC Server on Ubuntu 20.04, configure it, and use it for remote desktop connections.

Preparation

All commands must be executed on behalf of the superuser.

If your firewall is enabled, you need to open ports for incoming VNC connections. For one connection, it is enough to open 5901 as shown below. If you need more concurrent connections, open 5902, 5903, etc.

ufw allow 5901/tcp

Installing TightVNC Server

Update system packages:

sudo apt update && sudo apt upgrade

The graphical environment is not installed by default on server versions of Ubuntu. Therefore, if we want to connect to a remote desktop, we need to install a graphical shell. Let’s install the TightVNC Server itself at the same time.

apt install xfce4 xfce4-goodies tightvncserver

Configuring TightVNC Server

Let's start the TightVNC Server for the first time. It will create the files necessary for work and ask to create a password.

vncserver

Set a password and confirm it. If you need to restrict remote desktop control, select a read-only password.

Now stop your TightVNC session to adjust other settings.

vncserver -kill :1

Open the TightVNC config file.

nano ~/.vnc/xstartup

Add the following line to the end.

startxfce4

And start the server again.

vncserver

Setting up autorun

By default, TightVNC does not have a daemon and does not turn on after a system reboot. To fix this, let's create a new unit in systemd.

nano /etc/systemd/system/vncserver.service

Insert the following config there:

[Unit]
Description=TightVNC server
After=syslog.target network.target
[Service]
Type=forking
User=root
PAMName=login
PIDFile=/root/.vnc/%H:1.pid
ExecStartPre=-/usr/bin/vncserver -kill :1 > /dev/null 2>&1
ExecStart=/usr/bin/vncserver
ExecStop=/usr/bin/vncserver -kill :1
[Install]
WantedBy=multi-user.target

Screenshot 1. Configuration file
Reload systemd:

systemctl daemon-reload

Enable autorun of the TightVNC server and start it.

systemctl enable --now vncserver

Connecting to a remote desktop

Start any VNC client. For Windows, you can use RealVNC or TightVNC Viewer. For Linux - Remmina. Use the IP address of your server with port 5901 as the VNC server.

Screenshot 2. Launching the VNC client.

Enter the password you created earlier and you will see the remote desktop.

To secure the connection — see How to Establish VNC Connection over SSH Tunnel on Ubuntu 20.04.