Linux Mint

Install VNC Server on Linux Mint 20

Sometimes, you not only need to connect to remote systems but also need to access the entire GUI environment. In Linux, VNC is such a tool that allows you to log in to the Linux server graphically remotely. VNC (Stands for Virtual Network Computing) is similar to the remote desktop tool in Windows systems. It enables you to manage and control the remote server from your local system.

In this tutorial, we will describe how to install the VNC server on the Linux Mint 20 system. To test the connection to the VNC server, we will use the VNC viewer (VNC client) application. You can use any other VNC client application.

Before proceeding towards the article, make sure you are logged in as a sudo user.

Step 1: Install the Desktop environment

There are several desktop environments in Linux, such as Gnome, KDE, XFCE, Unity, etc. We will need to install any one of them for the VNC server to work properly. Here, we are going to install the XFCE desktop.

Open the command-line Terminal application using the Ctrl+Alt+T keyboard shortcut and then issue the following command in Terminal to install XFCE desktop.

$ sudo apt install xfce4 xfce4-goodies

After running the above command, the system might ask for confirmation that if you want to continue the installation or not. Press y to continue; after that, XFCE desktop will be installed on your system along with all dependencies.

Step 2: Install VNC server

There are different VNC servers available for Linux systems. Here, we are going to install “Tightvncserver”. It is pretty easy to set up and run Tightvncserver, and it is also reliable. Issue the following command in Terminal to install Tightvncserver.

$ sudo apt install -y tightvncserver

After the installation is completed, issue the following command in Terminal:

$ vncserver

You will be prompted to set a password for the VNC server. Enter the password and then confirm it by entering it again. Then you will be asked that if you want to enter a view-only password, hit n. If you press y, you will not be able to use the mouse and keyboard for controlling the VNC instance.

When you run the “vncserver” command for the first time, it creates a new directory “.vnc” under your Home directory. To view this directory, you can issue the following command in Terminal:

$ ls -lah ~/.vnc/

To view the VNC server process, issue the following command in Terminal:

$ ps -ef | grep Xtightvnc

Step 3: Configure VNC

Now we will configure the VNC server. For that, first, kill the VNC session using the following command in Terminal:

$ vncserver -kill :1

The default configuration file of the VNC server is ~/ .vnc/xstartup. Before making any changes to this file, let’s create a backup copy of this file. Issue the following command in Terminal to do so:

$ mv ~/.vnc/xstartup ~/.vnc/xstartup.backup

Now edit the ~/.vnc/xstartup file using any text editor. Here, we are using Vim text editor:

$ sudo vim ~/.vnc/xstartup

Insert the following lines in this file:

#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

Now hit Esc key and press :wq to save and close the ~/.vnc/xstartup file.

Now you will need to make this file executable. Issue the following command in Terminal to do so:

$ chmod +x ~/.vnc/xstartup

Run VNC server using the following command in Terminal:

$ vncserver

Step 4: Configure VNC as a service

Now you will need to create a service file for the VNC server. For this purpose, navigate to the /etc/systemd/system directory using the following command:

$ cd /etc/systemd/system

Then create a service file with the following command in Terminal:

$ vim vncserver@.service

Insert the following lines in this file:

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=edward
PIDFile=/home/edward/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target

Now hit Esc key and press :wq to save and close the file.

Now reload the systemd processes using the following command in Terminal:

$ systemctl daemon-reload

Then start the VNC server services:

$ systemctl start vncserver@1.service

To enable the VNC server service to start at boot, use the following command:

$ systemctl enable vncserver@1.service

To check the VNC service status, use the following command:

$ systemctl status vncserver@1.service

Step 5: Connect to VNC server

Now we will try to connect to the VNC server through an SSH tunnel as VNC itself is not an encrypted protocol. Issue the following command in Terminal to do so:

$ ssh -L 5901:127.0.0.1:5901 -N -f -l [user_name] [server_ip]

Replace the [user_name] and [server_ip] with the actual user name and the IP address of the VNC server. In our example, the command would be:

$ ssh -L 5901:127.0.0.1:5901 -N -f -l kbuzdar 192.168.72.159

This command will set up a secure tunnel between your localhost and the VNC server.

Now install VNC client application (VNC viewer )on your system and launch it. In the top bar of a VNC viewer, type 127.0.0.1:5901, and press Enter.

When the following dialog appears, click Continue.

In the following Authentication dialog, type VNC server password and click OK.

Now you will see the remote system’s desktop.

VNC server connection has successfully established now. Once you are finished, close the VNC viewer application and also kill the SSH tunnel by using the Ctrl+c in the Terminal window. If you need to connect to the VNC server again, first create the tunnel and then connect to the VNC server using the VNC viewer application.

In this article, you have learned how to install the VNC server on the Linux Mint 20 system. Now you can easily manage Linux Mint from your local system using the GUI interface. I hope you liked the article!

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.