# How to set up a VNC server on Ubuntu 24.04 step by step

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 prerequisites

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](https://www.ionos.com/digitalguide/server/know-how/what-is-a-vps-virtual-private-server/) or a [dedicated server](https://www.ionos.com/digitalguide/server/know-how/what-is-a-dedicated-server/). You also need a user account with [sudo](https://www.ionos.com/digitalguide/server/configuration/linux-sudo-command/) privileges so you can install the packages you’ll need.

To access the server through a graphical desktop, the server needs a **desktop environment**. If your server does not have one yet, you can install a lightweight option such as Xfce. It uses far fewer resources than full desktop environments like GNOME, which makes it a good choice for servers.

The startup script below requires Xfce. If it is not installed, install it before continuing:

```bash
sudo apt install xfce4 dbus-x11 -y
```

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](https://www.ionos.com/digitalguide/server/know-how/what-is-an-ip-address/). If you connect through an SSH tunnel, you do not need to open the VNC port in the firewall.

## Step 2: Update the Ubuntu server

Before starting the installation, make sure your Ubuntu server is up to date. Use the following terminal commands to update it:

```bash
sudo apt update
sudo apt upgrade -y
```

## Step 3: Install TigerVNC

On Ubuntu 24.04, TigerVNC is a good choice because it is actively maintained and provides stable remote connections. 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 performance and supports encrypted connections. TigerVNC is also relatively easy to configure, which makes it suitable for beginners.

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

After installation is complete, the vncserver command becomes available.

## Step 4: Set the VNC password

Start by setting a [secure password](https://www.ionos.com/digitalguide/server/security/protect-sensitive-data-with-a-strong-password/) for VNC:

```bash
vncpasswd
```

You will be asked to enter a password. TigerVNC only uses the first eight characters, so make sure those characters 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 configuration automatically. Then stop the session again:

```bash
vncserver :1
vncserver -kill :1
```

## Step 5: Create the VNC startup configuration

Create a **configuration file** so TigerVNC knows which desktop environment to load when a session starts. We’ve used the nano text editor, but feel free to use any text editor you like.

```bash
nano ~/.vnc/xstartup
```

Insert the following into the file:

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

Then save it and exit the editor. This configuration launches the Xfce interface automatically whenever the VNC session starts. Now use the following command to make the file executable:

```bash
chmod +x ~/.vnc/xstartup
```

## Step 6: Start the VNC server

Start the VNC server again:

```bash
vncserver :1
```

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:

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

The display number determines the network port used for the connection. Display :1 uses port 5901, display :2 uses port 5902, and so on. You will need this port number later when connecting 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 connection through an encrypted SSH connection, 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 connecting to the server using the following command:

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

Note The SSH connection must **remain active for as long as you use the VNC session**. If the SSH connection closes, the tunnel closes as well and the VNC client loses its connection 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 successfully, the SSH connection 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:

```text
localhost:5901
```

Some VNC clients also support the shorter format:

```text
localhost:1
```

Both addresses point to the same VNC session. After the connection is established, 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 connections 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 configuration 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 interfaces the server listens on. For remote access, using an SSH tunnel is therefore recommended. It lets you connect to the VNC server without exposing the VNC port externally, while also protecting the connection through encryption and strong authentication.

## Step 8: Start the VNC server automatically (optional)

To make the VNC server available automatically 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:

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

Insert the following into the file you created:

```systemd
[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
```

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 permissions. Then reload systemd so it recognizes the new service file, and enable the service:

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

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

```bash
vncserver -kill :1
```

Then start the service manually:

```bash
sudo systemctl start vncserver@1
```

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

```bash
sudo systemctl status vncserver@1
```

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


This is a markdown version of: [https://www.ionos.com/digitalguide/server/configuration/vnc-server-ubuntu-2404/](https://www.ionos.com/digitalguide/server/configuration/vnc-server-ubuntu-2404/) for AI/LLM consumption.