How To

Install VNC on Ubuntu 18.04: Step-by-Step TigerVNC Setup

A remote desktop interface makes it easy to manage a remote computer. VNC (Virtual Network Computing) is a protocol that shares the graphical desktop of a server over the network. It allows you to use your mouse and keyboard to control applications on a remote system.

This guide will show you how to install VNC on Ubuntu 18.04 using TigerVNC. We will set up a lightweight desktop environment and show you how to connect securely.

Install a Desktop Environment and TigerVNC

Most servers do not come with a graphical desktop interface. We will install Xfce, which is a fast, lightweight desktop environment that works well over slow connections.

Open your terminal and update your package lists:

bashsudo apt update

Install Xfce and the TigerVNC packages:

bashsudo apt install xfce4 xfce4-goodies tigervnc-standalone-server tigervnc-common

Once the installation is complete, run the password setup command:

bashvncpasswd

Enter a secure password when prompted. You can choose to create a view-only password. This is useful if you want to share your screen with others without letting them control the mouse.

Configure the VNC Startup Settings

We need to tell the VNC server which desktop environment to load when it starts up.

Create the configuration directory and file:

bashmkdir -p ~/.vncnano ~/.vnc/xstartup

Paste the following script into the file:

bash#!/bin/bashxrdb $HOME/.Xresourcesstartxfce4 &

Save the file and exit the editor. Make the startup script executable:

bashchmod +x ~/.vnc/xstartup

Set Up a System Service for VNC

Creating a service file allows you to run VNC automatically when the system boots.

Create the service file:

bashsudo nano /etc/systemd/system/vncserver@.service

Add the following configuration. Replace your_username with your actual system username:

ini[Unit]Description=Start TigerVNC server at startupAfter=syslog.target network.target[Service]Type=forkingUser=your_usernameExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%iExecStop=/usr/bin/vncserver -kill :%i[Install]WantedBy=multi-user.target

Enable and start the service on display port 1:

bashsudo systemctl daemon-reloadsudo systemctl enable vncserver@1sudo systemctl start vncserver@1

Connect to Your Remote Desktop Securely

VNC does not encrypt network traffic. To protect your password and data, you should tunnel the connection through SSH.

On your local machine, run this command to create an SSH tunnel:

bashssh -L 59000:localhost:5901 -N -f your_user@your_server_ip

Open your local VNC viewer software and connect to localhost:59000. You will be prompted for the VNC password you set earlier.

You now have a secure VNC desktop session running on your Ubuntu 18.04 server. Using an SSH tunnel ensures your credentials and data remain private over public networks. If you have any feedback or questions, leave a comment below.

Cyber Defence

Recent Posts

xargs Command in Linux: Build and Execute Commands from Input

The xargs command in Linux reads items from standard input and passes them as arguments to another…

1 day ago

locate Command in Linux: Find Files Fast with a Database Search

The locate command in Linux searches for files and directories by name. It queries a pre-built database…

1 day ago

Listing Linux Services with systemctl: A Complete Guide

Most modern Linux distributions use systemd as the default service manager. Knowing how to list…

1 day ago

How to Truncate Files in Linux: Empty Files Without Deleting

Truncating a file in Linux means removing its contents while leaving the file itself in…

1 day ago

ss Command in Linux: Display Socket Statistics and Connections

The ss command in Linux lists open sockets and active network connections. It replaced the deprecated netstat command and…

2 days ago

ftp Command in Linux: Connect to Servers and Transfer Files

The ftp command in Linux connects to a remote FTP server and transfers files. FTP transmits everything…

2 days ago