VNC stands for “Virtual Network Computing” is the set of protocols for sharing desktop systems remotely. There are many software available to access Linux based desktop remotely including, TigerVNC, TightVNC, Vino, vnc4server and many more.

TigerVNC is a free, open-source and high-performance VNC server used to control or access Linux based desktop systems remotely. It is a client/server application that allows you to interact with graphical applications on remote machines.

This tutorial described you to how to install and configure VNC server on Ubuntu 18.04 Linux system..

Prerequisites

By default, Ubuntu Server does not include a Desktop Environment. TigerVNC server is designed to controls only desktop systems. So you will need to add a desktop environment in your server.

First, update and upgrade all installed packages with the following command:

sudo apt update && apt upgrade 

Once your system is updated, install the tasksel utility to install a desktop environment:

sudo apt install tasksel -y 

After installing Tasksel, launch the Tasksel utility with the following command:

sudo tasksel 

You should see the following interface:

How To Install and Configure VNC on Ubuntu 18.04 General Articles Ubuntu 18.04 vnc vncserver vncviewer

Use the arrow key to scroll down the list and find Ubuntu desktop. Next, press the Space key to select it then press the Tab key to select OK then hit Enter to install the Ubuntu desktop.

Once all the packages are installed, you will need to set your system boots into the graphical target. You can set it with the following command:

sudo systemctl set-default graphical.target 

Next, restart your system to apply the changes.

Step 2 – Install VNC Server on Ubuntu 18.04

The default Ubuntu 18.04 apt repositories contains TigerVNC server package. You can install it by just running the following command:

sudo apt install tigervnc-standalone-server -y 

After installing TigerVNC, create a new user and set a VNC password for that user.

First, create a new user named tecadmin with the following command:

sudo adduser tecadmin 

Next, switch the user to tecadmin and set a VNC password with the following command:

su - tecadmin
vncpasswd 

Provide your desired password as shown below:

Password:
Verify:
Would you like to enter a view-only password (y/n)? n

Next, start the VNC server using the following command:

vncserver -localhost no 

Once the VNC server is started, you should get the following output:

/usr/bin/xauth:  file /home/tecadmin/.Xauthority does not exist

New 'ubuntu1804:1 (tecadmin)' desktop at :1 on machine ubuntu1804

Starting applications specified in /etc/X11/Xvnc-session
Log file is /home/tecadmin/.vnc/ubuntu1804:1.log

Use xtigervncviewer -SecurityTypes VncAuth,TLSVnc -passwd /home/tecadmin/.vnc/passwd ubuntu1804:1 to connect to the VNC server.

You can verify your running VNC server using the following command:

vncserver -list 

You should get the following output:

TigerVNC server sessions:

X DISPLAY #     PROCESS ID
:1              30982

Step 2 – Installing VNC Client

In this section, we will install the RealVNC VNC client on the remote machine and connect to the VNC server.

You can download the RealVNC client from the RealVNC download page. Make sure to select correct system architecture. Default page downloads 32bit package.

Once the download is completed, install the downloaded package with the following command:

sudo dpkg -i ~/Downloads/VNC-Viewer-6.20.529-Linux-x64.deb  

Next, launch the VNC client from the Gnome application menu. Then, Click on the File menu => New connection to create a new connection. You should see the following screen:

How To Install and Configure VNC on Ubuntu 18.04 General Articles Ubuntu 18.04 vnc vncserver vncviewer

Provide the Name and IP address along with VNC session ID :1 of your VNC server and click on the OK to save the connection. You should see your saved connection in the following screen:

How To Install and Configure VNC on Ubuntu 18.04 General Articles Ubuntu 18.04 vnc vncserver vncviewer

Now, double click on your newly created connection. You will be asked to provide your VNC password as shown below:

How To Install and Configure VNC on Ubuntu 18.04 General Articles Ubuntu 18.04 vnc vncserver vncviewer

Provide your VNC password and click on the OK. Once connected, you should see your Ubuntu desktop screen:

How To Install and Configure VNC on Ubuntu 18.04 General Articles Ubuntu 18.04 vnc vncserver vncviewer

Step 3 – Setup VNC for Your Desktop Environment

Before starting, stop the VNC instance using the vncserver command with a -kill option and the server session ID as an argument.

sudo vncserver -kill :1 

You should get the following output:

Killing Xtigervnc process ID 1719… success!

Next, you will need to configure TigerVNC to work with Gnome. You can do it by creating new file xstartup inside .vnc directory:

su - tecadmin 
nano ~/.vnc/xstartup 

Add the following lines:

#!/bin/sh

exec /etc/vnc/xstartup

xrdb $HOME/.Xresources

vncconfig iconic &

dbuslaunch exitwithsession gnomesession &

Save and close the file when you are finished. The above script will be executed automatically whenever you start or restart the TigerVNC server.

Next, give execute permissions to the ~/.vnc/xstartup file:

chmod u x  ~/.vnc/xstartup 

Step 5 – Create a Systemd Service File for VNC

Next, you will need to create a systemd file for TigerVNC to manage the VNC service. You can create it with the following command:

sudo vim /etc/systemd/system/[email protected] 

Add the following lines:

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
User=tecadmin
PAMName=login
PIDFile=/home/%u/.vnc/%H%i.pid
ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :
ExecStart=/usr/bin/vncserver :%i -localhost no -geometry 1024x768
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Save and close the file then reload the systemd daemon with the following command:

sudo systemctl daemon-reload 

Next, enable the VNC service to start at system reboot with the following command:

sudo systemctl enable [email protected] 

Next, start the VNC service with the following command:

sudo systemctl start [email protected] 

Conclusion

Congratulations! you have successfully installed and setup the VNC server on Ubuntu 18.04 LTS Linux system. You can now connect Ubuntu Desktop from remote system using vnc viewer.