In this article, we’ll learn how to install and configure a Virtual Network Computing (VNC) server on Ubuntu 22.04 and 20.04. VNC allows you to access a remote desktop environment from another computer to control and manage your Ubuntu system remotely. Follow along as we go through the steps to set up a VNC server on your Ubuntu machine.
Table of Contents
Before we begin, ensure that you have the following:
- A system is running Ubuntu 22.04 or 20.04.
- Access to a user account with sudo privileges.
Step 1: Installing the VNC Server
To get started, follow these steps to install the VNC server on your Ubuntu machine:
1.1. Update and upgrade the system
First, update your package list and upgrade your system by running the following commands:
sudo apt update
sudo apt upgrade
1.2. Install the VNC server software
Next, install the TightVNC server package:
sudo apt install tightvncserver
Step 2: Configuring the VNC Server
With the VNC server installed, we’ll now configure it:
2.1. Create a new VNC user
Create a new user specifically for VNC connections. Replace
vncuser with your desired username:
sudo adduser vncuser
2.2. Configure the VNC password
Log in as the new VNC user and set a password for the VNC connection:
su - vncuser vncpasswd
2.3. Set up the VNC session
Create a new VNC session for the user by running the following command:
This will create a new VNC session on display number 1.
Step 3: Configuring the Firewall
To allow VNC connections, you’ll need to configure your firewall:
3.1. Open the necessary ports
Open the necessary ports on your firewall for the VNC server:
sudo ufw allow 5901/tcp
Step 4: Starting the VNC Server
Now that everything is set up start the VNC server:
Step 5: Connecting to the VNC Server
With the VNC server running, you can now connect to it from another computer:
5.1. Install a VNC client
5.2. Connect to the VNC server
Open your VNC client and enter the server address in the following format:
IP_ADDRESS_OF_YOUR_SERVER With the actual IP address of your Ubuntu machine running the VNC server. You will then be prompted to enter the password you set up earlier.
Step 6: Securing Your VNC Connection
To ensure the security of your VNC connection, it’s recommended to use SSH tunneling:
6.1. Use SSH tunneling
On the client machine, create an SSH tunnel with the following command:
ssh -L 5901:localhost:5901 -N -f -l vncuser IP_ADDRESS_OF_YOUR_SERVER
vncuser with your VNC username and
IP_ADDRESS_OF_YOUR_SERVER with the actual IP address of your Ubuntu machine running the VNC server.
When connecting with your VNC client, use
localhost:1 the server address instead of the actual IP address.
Congratulations! If you have done everything right (as described above), you can now remotely access and manage your stuff from another computer. Remember to use SSH tunneling to secure your VNC connection.
Can I use a different VNC server software?
Can I connect to the VNC server from a different operating system?
Yes, VNC clients are available for various operating systems, including Windows, macOS, and Linux. Ensure you have a compatible VNC client installed on your computer to connect to the VNC server.
Can I set up multiple VNC sessions?
Yes, you can create multiple VNC sessions by changing the display number in the
vncserver command. For example, to create a session on display number 2, use
How do I stop the VNC server?
To stop the VNC server, use the following command, replacing
:1 with the appropriate display number:
vncserver -kill :1
Can I change the resolution of the VNC session?
Yes, you can modify the VNC session’s resolution by editing the
~/.vnc/xstartup file and adding the following line before the
xrandr -s WIDTHxHEIGHT
HEIGHT with the desired resolution values.