The best way to Set up and Run a VNC Server on Ubuntu Linux

Accessing a computer through a remote desktop is an important part of working life. Remote desktop programs allow you to access and control other systems that are not physically available to you. Working from home has made remote computing even more relevant as people from distant regions can work remotely with their computers.

This guide shows that you need to install a VNC (Virtual Network Computing) server on Ubuntu 20.04 LTS to enable remote computing on your system.

What is a VNC server?

Traditionally, Linux computers access other systems through the terminal using utilities such as Secure Shell (SSH). However, the only challenge with the command line interface is that you cannot interact with the other PC through a graphical user interface. A VNC connection is ideal here.

A Virtual Network Computing Server, commonly known as a VNC server, is a system that allows you to remotely access and interact with another PC over a network using a graphical interface. Many VNC applications have been developed; Some of them include TightVNC, TigerVNC, and RealVNC. In this guide we will use the x11vnc Server for setting up remote computing on our Ubuntu system.

X11vnc is a lightweight VNC server that does not create an additional display for the remote desktop. Instead, it shows the existing x11 display (KDE, GNOME, Xfce, etc.) of your Linux system in real time. Another benefit of x11vnc is that you can connect to any VNC client or viewer.

The x11vnc server has built-in SSL / TLS encryption and 2048-bit RSA authentication, including VeNCrypt support and the UNIX account and password login system.

Install a compatible display manager

Ubuntu Linux uses the GNOME Desktop Manager (GDM) as the default display manager. Use newer versions of Ubuntu gdm3. Unfortunately, GDM usually doesn't work very well with the x11vnc server. To overcome this, you need to install the Light Display Manager or lightdm.

Open the terminal with the Ctrl + Alt + T. Keyboard shortcuts. First update your software sources with suitable.

sudo apt update

Then install lightdm using the command given below:

sudo apt install lightdm

The following screen will appear during the installation process. Press the Enter Key on your keyboard to continue.

Next, choose the lightdm Option and press Enter on your keyboard.

Restart your PC for the display manager changes to take effect.

restart sudo

You will notice a slight change in the login screen after the reboot as you are using that now lightdm as your display manager.

Installation of x11vnc server on Ubuntu

To install the x11nvc server, open your system terminal by pressing Ctrl + Alt + T.. Then run the following command.

sudo apt install x11vnc

Configure the x11vnc server

You are now configuring a service that will be used to start the x11nvc server. Create a file named x11nvc.service by doing /lib / systemd / system / Directory. Vim is used in this guide. However, you can also use any other Linux text editor of your choice, e.g. Nano.

sudo vim /lib/systemd/system/x11vnc.service

Copy and paste the following content into the newly created service file.

(Unit) description = x11vnc service
After = display-manager.service
network.target syslog.target
(Service)
Type = simple
ExecStart = / usr / bin / x11vnc -forever -display: 0 -auth rate -passwd randompassword
ExecStop = / usr / bin / killall x11vnc
Restart = on error
(To install)
WantedBy = multi-user.target

The text Randompassword is the password you use to log into your server. Edit it and set it to your preferred strong password.

Related: How To Make A Strong Password That You Will Not Forget

Simply put, the text in the service file says: This is a child service and the system should start this service after all other services have started. In the event of an error, the service should restart itself before the process reaches the multi-user goal.

If you are using Vim, press the button Esc Key. Then enter : wq followed by the Enter Button to save changes and exit the Vim editor.

After saving the file, make sure to reload the file systemd Manager configuration and device files.

systemctl daemon-reload

Then activate the x11vnc service.

systemctl enable x11vnc.service

Finally, start the VNC server with the following command.

sudo systemctl start x11vnc.service

Check the status of the x11vnc service with systemctl.

systemctl status x11vnc.service

The output should be similar to the one shown below.

As you can see from the output above, the service is up and running.

Another important point is the port that the x11vnc server is using (in this case port 5900).

Activate the server port in your firewall

Ubuntu uses the ufw Firewall by default. Enter the following command to allow other PCs to access the Ubuntu system through the port used by the x11vnc server.

sudo ufw allow 5900 / tcp

Connect from another computer

You can now connect to your Ubuntu system using a remote desktop connection using VNC.

You can use any VNC client to connect to the Ubuntu Linux PC. One of the recommended VNC viewers is VNC Connect by RealVNC. It's available for almost all major platforms including macOS, Linux, Windows, iOS, Android, etc.

Download: VNC Viewer from RealVNC

After the download, install the VNC client on your system and start the application.

This guide uses the macOS installation of VNC Connect, but the process is similar for other operating systems as well.

Enter the IP address of the PC you want to connect to, followed by the port number used by the x11vnc server. Then press the button Enter Key on your keyboard to connect.

Note: In Ubuntu, you can get your IP address by typing the following command.

ip addr

The VNC connection is not encrypted, so anyone eavesdropping on the network can access and view the data without any problems. However, the password is encrypted. The VNC client warns you about the unencrypted connection. Choose Continue Button to continue.

On the next screen you will be asked to enter a password. This is the password you set in the field x11vnc.service File above. Enter the password accordingly and press OK Button to continue.

You can now access your PC from another device.

Deactivating the screen lock

One of the problems with using the x11vnc server is the screen lock. However, you can easily fix this problem by turning off the screen lock on your PC.

Go over to Settings> Privacy> Screen lock and make sure you disable that Automatic screen lock and Lock screen when paused Options.

Note: This is a potential security risk. So activate it again later.

Work remotely on your Linux computer

Remote desktop programs are an important part of your life when working remotely. Even if a VNC server is set up on your system, you cannot access the system without a VNC client. With a VNC server installed on your Linux PC, you can access your system from other devices anytime, anywhere.

Operating systems are not a limitation when it comes to remote computing. For almost every operating system, there are several applications available that you can use to set up a VNC server on your computer.

Top 10 remote access software to control your Windows PC from anywhere

What do you do when you need to work on one computer across locations? Use this remote access software to connect to another PC from anywhere.

Continue reading

About the author

Mwiza Kumwenda
(11 articles published)

Mwiza is a professional developer of software and writes extensively on Linux and front-end programming. Some of his interests include history, economics, politics, and enterprise architecture.

More
By Mwiza Kumwenda

Subscribe to our newsletter

Sign up for our newsletter to receive tech tips, reviews, free e-books, and exclusive offers!

One more step …!

Please confirm your email address in the email we just sent you.

Leave a Reply

Your email address will not be published. Required fields are marked *