Newsletter Subscribe
Enter your email address below and subscribe to our newsletter
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:
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
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:
vncserver :1
This will create a new VNC session on display number 1.
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
Now that everything is set up start the VNC server:
vncserver :1
With the VNC server running, you can now connect to it from another computer:
5.1. Install a VNC client
On the computer, you’ll use to connect to the VNC server and install a VNC client like RealVNC Viewer, TightVNC Viewer, or TigerVNC Viewer.
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:1
Replace 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.
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
Replace 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.
Yes, multiple VNC server software options are available, such as x11vnc and RealVNC Server. The installation and configuration process may vary depending on the software you choose.
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.
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 vncserver :2
.
To stop the VNC server, use the following command, replacing :1
with the appropriate display number:
vncserver -kill :1
Yes, you can modify the VNC session’s resolution by editing the ~/.vnc/xstartup
file and adding the following line before the x-window-manager
command:
xrandr -s WIDTHxHEIGHT
Replace WIDTH
and HEIGHT
with the desired resolution values.