In­stalling a VNC server on Ubuntu 22.04 gives you the op­por­tun­ity to access your Linux desktop from anywhere. Whether you’re working from home, on a business trip or just want to work from another room — with a VNC server, you’ll always have access to your work en­vir­on­ment.

What are the ad­vant­ages of a VNC server on Ubuntu 22.04?

Using a VNC server on Ubuntu 22.04 offers many op­por­tun­it­ies to make everyday work a lot easier. With a VNC server, you can access your Ubuntu desktop from anywhere in the world. This means you don’t have to be at your desk to manage your ap­plic­a­tions and data. This flex­ib­il­ity is extremely con­veni­ent for remote workers, business trav­el­lers or people who want to work from different locations. What’s more, setting up a VNC server is re­l­at­ively easy, so even less tech-savvy users can quickly establish a func­tion­ing remote con­nec­tion.

A VNC server also promotes col­lab­or­a­tion within teams. It allows multiple members sim­ul­tan­eous access to the same desktop. This allows teams to work together ef­fect­ively re­gard­less of their location, to work on projects together and to solve problems in real time. IT ad­min­is­trat­ors and support can also resolve errors remotely without having to be on site. This saves time and costs for travel and ad­di­tion­al ap­point­ments. In terms of security, many VNC servers on Ubuntu 22.04 have robust options. Encrypted con­nec­tions and various au­then­tic­a­tion methods protect your data and ensure that only au­thor­ised people have access to your system.

These are the re­quire­ments for a VNC server on Ubuntu 22.04

First, you need a working in­stall­a­tion of Ubuntu 22.04. Many VNC servers are fully com­pat­ible with this operating system and all required packages and de­pend­en­cies are provided in the official Ubuntu re­pos­it­or­ies. Make sure your system is up to date to avoid possible com­plic­a­tions during in­stall­a­tion. In general, you should fulfill the following re­quire­ments:

  • Ubuntu 22.04: A working and up-to-date in­stall­a­tion of Ubuntu 22.04.
  • Network con­nec­tion: A stable Ethernet or WLAN con­nec­tion for remote access.
  • Root au­thor­isa­tions: The VNC server user requires root rights for in­stall­a­tion and con­fig­ur­a­tion.
  • Software package: In­stall­a­tion of VNC server software, such as TigerVNC, RealVNC or x11vnc from the Ubuntu re­pos­it­or­ies.
  • Desktop en­vir­on­ment: The required desktop en­vir­on­ment (e.g., GNOME, XFCE) should be installed.
  • Firewall con­fig­ur­a­tion: Open port 5900 or adjust the firewall rules to allow VNC traffic.
Free VPS Trial
Try a virtual server risk-free for 30 days

Try out your VPS for 30 days. If you're not satisfied, we'll fully reimburse you.

How to install a VNC Server on Ubuntu 22.04

There are many options when it comes to choosing a VNC server and desktop en­vir­on­ment. In this tutorial, we’ll install the latest packages for the XFCE desktop en­vir­on­ment and the TigerVNC package available in the official Ubuntu re­pos­it­ory. XFCE and TigerVNC both require few resources and have fast per­form­ance. As a result, the VNC con­nec­tion remains smooth and stable even with slower internet con­nec­tions.

Step 1: Update packages

Before you start the in­stall­a­tion, make sure that your system is up to date. Execute the following commands to install all available updates:

sudo apt update
sudo apt upgrade
bash

Step 2: Install the desktop en­vir­on­ment

The VNC server requires a desktop en­vir­on­ment as it provides the desktop over the network. Ubuntu 22.04 comes with GNOME by default, but you can also install other desktop en­vir­on­ments such as XFCE, which is par­tic­u­larly light­weight.

sudo apt install xfce4 xfce4-goodies
bash

The xfce4-goodies package contains ad­di­tion­al useful tools and plugins for XFCE.

Step 3: Create a new user

After you have installed the desktop en­vir­on­ment, you must create a new user to operate the VNC server. It’s advisable not to do this as a root user to ensure security. In this case, we’ll create a new user with the name ‘john’ and give him the necessary per­mis­sions to run the VNC server under this user account.

First, you must create the user ‘john’ and assign him a password. You can do this with the following commands:

sudo useradd -m -s /bin/bash john
sudo passwd john
bash

The command sudo useradd -m -s /bin/bash john creates a new user ‘john’ and sets up a home directory, setting the default shell to /bin/bash. Then use sudo passwd john to set a password for this user. It’s essential to choose a secure password.

After the user has been created, you must add it to the sudo group so that it can execute ad­min­is­trat­ive commands. You do this with the following command:

sudo usermod -aG sudo john
bash

This command enables ‘john’ to execute commands with extended rights that are provided with sudo.

To check whether ‘john’ has the correct au­thor­isa­tions, log in as ‘john’ and test the root rights. To do this, execute these commands:

su - john
sudo su
bash

With su - john you switch to the user ‘john’ and with sudo su you gain root rights, provided the password was entered correctly. If the au­then­tic­a­tion is suc­cess­ful, you’ll see a prompt such as root@hostname, which confirms that you have root rights.

Step 4: Install the VNC server software

For this tutorial, we’ll use TigerVNC as it’s a widely used and well-supported VNC server option. Install TigerVNC with this command:

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

This entry installs the VNC server software as well as some necessary common packages that are required for operation.

Step 5: Create the VNC server instance

Before you can start the VNC server, you must set a password that’s required to access the VNC server. Enter the following command in the terminal:

vncserver
bash

You’ll be asked to enter and confirm a password. This password protects access to your VNC server. You can also select an option to set a view-only password if you want other users to only see the screen but not have control.

When the server is started for the first time, a new display is created, typically :1. The output shows the exact number of the display that you can use.

Here’s an example:

New 'X' desktop is your-machine-name:1
bash

Make a note of the display number (in this case :1), as you’ll need this to connect to the VNC client.

Step 6: Configure the VNC server instance

Create a con­fig­ur­a­tion file for the VNC server to ensure that XFCE is loaded when the VNC server is started. The file ~/.vnc/xstartup can have the following content, for example:

#!/bin/sh
# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/usr/bin/startxfce4
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
x-window-manager &
bash

The file becomes ex­ecut­able when you use this command:

chmod +x ~/.vnc/xstartup
bash

Step 7: Run VNC server as a system service

By setting up the VNC server as a Systemd service, you can start, stop and restart it like any other service. You can also use Systemd commands to start the VNC server auto­mat­ic­ally when the system boots up.

First, create a new file with a text editor of your choice:

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

Add the following content to the file:

[Unit]
Description=Start TigerVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=<your-username>
PAMName=login
PIDFile=/home/<your-username>/.vnc/%H:%i.pid
ExecStart=/usr/bin/vncserver %i
ExecStop=/usr/bin/vncserver -kill %i
[Install]
WantedBy=multi-user.target
bash

Replace <your-username> with your actual username. Load the new service file and activate the service:

sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
sudo systemctl start vncserver@:1
bash

The command sudo systemctl enable vncserver@1.service activates the VNC server service for display :1 so that it starts auto­mat­ic­ally the next time the system is started. The systemd service file vncserver@.service is used for this, in which %i is replaced by 1. This makes it possible to configure the VNC server for the display :1 and to ensure that it starts every time the system boots. The command creates the necessary shortcuts to include the service in the correct startup process.

Step 8: Configure the firewall

If you have activated a firewall on your Ubuntu server, you must release the VNC port to allow remote con­nec­tions. By default, the VNC server uses port 5900, followed by the display number. So, for display :1 the port is 5901.

Open the port using ufw:

sudo ufw allow 5901/tcp
bash

Check the firewall rules to make sure that the port is open:

sudo ufw status
bash

Here’s an example of a possible output:

Status: active
To                              Action        From
--                                ------            ----
22/tcp                    	ALLOW       Anywhere
80/tcp                  	ALLOW       Anywhere
443/tcp                  	ALLOW       Anywhere
5901/tcp                	ALLOW       Anywhere
22/tcp (v6)             	ALLOW       Anywhere (v6)
80/tcp (v6)             	ALLOW       Anywhere (v6)
443/tcp (v6)           		ALLOW       Anywhere (v6)
5901/tcp (v6)         		ALLOW       Anywhere (v6)
bash

Step 9: Connect to the VNC server

To establish a con­nec­tion to your VNC server, you need a VNC client on your local computer. Popular VNC clients are RealVNC, TigerVNC Viewer and TightVNC Viewer. To improve the security of your VNC con­nec­tion, you should consider using an encrypted con­nec­tion via SSH. This protects the com­mu­nic­a­tion between your VNC client and the server.

Establish a con­nec­tion to your server via SSH and forward the VNC port:

ssh -L 59000:localhost:5901 -C -N -l <your-username>@<server-ip>
bash
  • ssh: The command for the secure con­nec­tion to a remote server via the SSH protocol, which transmits data in encrypted form.
  • -L 59000:localhost:5901: Enables local port for­ward­ing. Traffic from port 59000 on your local computer is forwarded through the SSH tunnel to port 5901 on the remote server. localhost refers to the remote server on which the VNC server is running.
  • C: Activates the com­pres­sion of data traffic. This can improve the trans­mis­sion speed and reduce bandwidth util­isa­tion, es­pe­cially with slow con­nec­tions.
  • N: Prevents commands from being executed on the remote server. This mode is useful if you only want to set up the tunnel without starting a shell on the remote server.
  • -l <your-username>: Specifies the username with which you log in to the remote server.
  • <server-ip>: The IP address or host name of the remote server to which you want to connect via SSH.
Note

Replace <your-username> with your username and <server-ip> with the IP address of your server.

Connect to the local port 5901 that you forwarded via the SSH tunnel by entering localhost:5901 in your VNC viewer.

This method guar­an­tees that your VNC con­nec­tion is made via an encrypted SSH con­nec­tion and is therefore more secure.

Step 10: Manage the VNC server

To stop or restart the VNC server, use the following commands:

Stop VNC server:

vncserver -kill :1
bash

Restart VNC server:

vncserver :1
bash

Exit VNC server (with systemd):

sudo systemctl stop vncserver@:1
bash

Check status:

sudo systemctl status vncserver@1
bash

One possible output could be:

vncserver@1.service - Start TigerVNC server at startup
      Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: enabled)
      Active: active (running) since Mon 2024-07-29 16:57:26 UTC; 20s ago
     Process: 97088 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=2)
     Process: 97092 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :1 (code=exited, status=0/SUCCESS)
    Main PID: 97103 (Xtigervnc)
        Tasks: 77 (limit: 4665)
      Memory: 146.7M
          CPU: 4.459s
      CGroup: /system.slice/system-vncserver.slice/vncserver@1.service
. . .
bash

Step 11: Troubleshoot­ing

If you encounter problems, check the following:

  • Log files: The log files for the VNC server are located in ~/.vnc. Check these files for error messages that may indicate possible problems.
  • Network con­nec­tion: Make sure that no network re­stric­tions or firewalls are blocking access to the VNC port.
  • Con­fig­ur­a­tion files: Make sure that there are no errors in the con­fig­ur­a­tion of the desktop en­vir­on­ment in the file ~/.vnc/xstartup.

You now have the option of con­veni­ently managing your files and programs as well as your system settings via a VNC server. If you prefer to use Windows, we recommend our tutorial ‘Install VNC server on Windows’.

Dedicated Server
Per­form­ance through in­nov­a­tion
  • En­ter­prise hardware
  • Con­fig­ur­able hardware equipment
  • ISO-certified data centres
Go to Main Menu