A VNC server lets you access and control the desktop interface on Ubuntu 24.04 remotely. Once it is set up, you can run programs, change settings and manage files as if you were sitting directly in front of the server.

Step 1: Check the pre­requis­ites

Before you install a VNC server, make sure Ubuntu 24.04 is installed and that you can access the terminal. You can do this locally or via SSH, for example on a VPS or a dedicated server. You also need a user account with sudo priv­ileges so you can install the packages you’ll need.

To access the server through a graphical desktop, the server needs a desktop en­vir­on­ment. If your server does not have one yet, you can install a light­weight option such as Xfce. It uses far fewer resources than full desktop en­vir­on­ments like GNOME, which makes it a good choice for servers.

The startup script below requires Xfce. If it is not installed, install it before con­tinu­ing:

sudo apt install xfce4 dbus-x11 -y
bash

You also need a VNC client on your local computer. Tools such as RealVNC Viewer or TigerVNC Viewer let you connect to the server using its IP address. If you connect through an SSH tunnel, you do not need to open the VNC port in the firewall.

VPS Hosting
VPS at an un­beat­able price – and better than ever
  • NEW: Flexible scaling with VM-cloning, load balancing, new storage options and more
  • Unlimited traffic and >99.99% avail­ab­il­ity
  • 24/7 expert support and your own personal con­sult­ant

Step 2: Update the Ubuntu server

Before starting the in­stall­a­tion, make sure your Ubuntu server is up to date. Use the following terminal commands to update it:

sudo apt update
sudo apt upgrade -y
bash

Step 3: Install TigerVNC

On Ubuntu 24.04, TigerVNC is a good choice because it is actively main­tained and provides stable remote con­nec­tions. TigerVNC is open-source software that lets you set up a VNC server and access an Ubuntu desktop remotely. It is a reliable option that offers good per­form­ance and supports encrypted con­nec­tions. TigerVNC is also re­l­at­ively easy to configure, which makes it suitable for beginners.

sudo apt install tigervnc-standalone-server tigervnc-common -y
bash

After in­stall­a­tion is complete, the vncserver command becomes available.

Step 4: Set the VNC password

Start by setting a secure password for VNC:

vncpasswd
bash

You will be asked to enter a password. TigerVNC only uses the first eight char­ac­ters, so make sure those char­ac­ters are strong. You can also set an optional view-only password.

Next, start the VNC server for the first time so it can create the basic con­fig­ur­a­tion auto­mat­ic­ally. Then stop the session again:

vncserver :1
vncserver -kill :1
bash

Step 5: Create the VNC startup con­fig­ur­a­tion

Create a con­fig­ur­a­tion file so TigerVNC knows which desktop en­vir­on­ment to load when a session starts. We’ve used the nano text editor, but feel free to use any text editor you like.

nano ~/.vnc/xstartup
bash

Insert the following into the file:

#!/bin/bash
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -r "$HOME/.Xresources" ] && xrdb "$HOME/.Xresources"
exec startxfce4
bash

Then save it and exit the editor. This con­fig­ur­a­tion launches the Xfce interface auto­mat­ic­ally whenever the VNC session starts. Now use the following command to make the file ex­ecut­able:

chmod +x ~/.vnc/xstartup
bash

Step 6: Start the VNC server

Start the VNC server again:

vncserver :1
bash

This command starts a new VNC session with the display number :1. Each display number has its own graphical session and uses a specific network port.

After starting the server, you should see output similar to this:

new Xtigervnc server 'server:1 (user)' on port 5901
text

The display number de­term­ines the network port used for the con­nec­tion. Display :1 uses port 5901, display :2 uses port 5902, and so on. You will need this port number later when con­nect­ing with your VNC client.

Step 7: Connect to the VNC server

Use an SSH tunnel to connect to the VNC server securely. This sends the VNC con­nec­tion through an encrypted SSH con­nec­tion, so you do not have to open the VNC port in the firewall or make it reachable from the internet. Start by opening a terminal on your local computer and con­nect­ing to the server using the following command:

ssh -L 5901:localhost:5901 USERNAME@IP-ADDRESS
bash
Note

The SSH con­nec­tion must remain active for as long as you use the VNC session. If the SSH con­nec­tion closes, the tunnel closes as well and the VNC client loses its con­nec­tion to the VNC server.

Replace USERNAME with your username on the server and IP-ADDRESS with your server’s public IP address. After you log in suc­cess­fully, the SSH con­nec­tion stays active and forwards all requests from your local port 5901 to the VNC server running on the remote server.

Then start your VNC client and enter the following address:

localhost:5901
text

Some VNC clients also support the shorter format:

localhost:1
text

Both addresses point to the same VNC session. After the con­nec­tion is es­tab­lished, enter the VNC password you set earlier. Your Ubuntu desktop should then appear in the VNC window, where you can use it like a regular desktop.

Note

TigerVNC can support encrypted con­nec­tions via TLS (for example, with the TLSVnc security type). TLS can be selected with -SecurityTypes; -localhost no also adds TLSVnc to the default security types. With the default con­fig­ur­a­tion and no command-line overrides, the tigervncserver wrapper uses only VncAuth and listens on localhost (127.0.0.1) by default. This means the VNC port cannot be accessed directly from outside the server. Without an explicit -localhost setting, the security types determine which in­ter­faces the server listens on. For remote access, using an SSH tunnel is therefore re­com­men­ded. It lets you connect to the VNC server without exposing the VNC port ex­tern­ally, while also pro­tect­ing the con­nec­tion through en­cryp­tion and strong au­then­tic­a­tion.

Step 8: Start the VNC server auto­mat­ic­ally (optional)

To make the VNC server available auto­mat­ic­ally after a reboot, you can create a systemd service. This starts the VNC session when the system boots, so you do not have to start the server manually each time. Start by creating a service file:

sudo nano /etc/systemd/system/vncserver@.service
bash

Insert the following into the file you created:

[Unit]
Description=VNC Server
After=network.target
[Service]
Type=forking
User=USERNAME
WorkingDirectory=/home/USERNAME
ExecStart=/usr/bin/vncserver -geometry 1280x800 -localhost yes :%i
ExecStop=/usr/bin/vncserver -kill :%i
Restart=on-failure
PIDFile=/home/USERNAME/.vnc/%H:%i.pid
[Install]
WantedBy=multi-user.target
systemd

Replace USERNAME with the username of the account that should run the VNC session. This makes sure the VNC server starts with the correct user per­mis­sions. Then reload systemd so it re­cog­nises the new service file, and enable the service:

sudo systemctl daemon-reload
sudo systemctl enable vncserver@1
bash

Stop the VNC session started in step 6 before starting the service:

vncserver -kill :1
bash

Then start the service manually:

sudo systemctl start vncserver@1
bash

Use the following command to check whether the service started correctly:

sudo systemctl status vncserver@1
bash

If the service is active, the VNC server will start auto­mat­ic­ally after each reboot. You can then open your VNC client whenever you need it and work with your Ubuntu desktop remotely.

Reviewer

Go to Main Menu