How To Install and Configure TigerVNC server on Ubuntu

How do I install and configure TigerVNC server on Ubuntu 18.04/20.04 for remote desktop access? How to enable Remote Desktop connection between two Ubuntu Linux systems (server and client) to access GUI? How to configure Virtual Network Computing (VNC) in Ubuntu Linux 18.04 LTS or 18.10 or 20.04/22.04 LTS server?

Introduction: VNC is an acronym for Virtual Network Computing. It is nothing but a Linux desktop sharing system or set of protocols for sharing desktop. One can use VNC to control or access Linux based desktop remotely. VNC works on client-server principal. There are many implementations of the VNC protocol for Linux or Unix like systems. Some typical examples are TigerVNC, TightVNC, Vino (default for Gnome desktop), x11vnc, krfb (default for KDE desktop), vnc4server and more. This page shows how to install and configure TigerVNC on Ubuntu 18.04/20.04/22.04 LTS Linux based system to get access to full Gnome 3 desktop.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Category System Management
OS compatibility Debian  Linux  Mint  Ubuntu
Est. reading time 5 minutes

Sample setup for installation of VNC server on Ubuntu

Sample setup for installation of VNC server on Ubuntu Linux
A VNC server located at 202.222.1.2 shares a desktop with other client computers or mobile devices over the Internet or LAN. You must install TigerVNC server on Ubuntu server.

Most common VNC application

  • Remote technical support
  • Access files from home computer or work computer stored on a remote server
  • Access remote Linux desktop stored in the cloud-based system
  • Troubleshooting server issues. One can control Linux server or desktop when networking service is down. All you need is out of band management with an embedded VNC server in BMC.

How to install and configure TigerVNC server on Ubuntu 18.04 LTS

The procedure to install and configure VNC server on Ubuntu Linux is as follows:

  1. Login to remote Ubuntu server using ssh command
  2. Install the desktop environment such as Gnome or XFCE4 using apt command
  3. Install and configure the TigerVNC server
  4. Connect to VNC server from your desktop using SSH and vnc client

Let us see all steps in details.

How to Install and Configure VNC on Ubuntu 18.04 or 18.10

Type the following apt command or apt-get command to install tigervnc vnc server on your server:
$ sudo apt install tigervnc-standalone-server tigervnc-xorg-extension tigervnc-viewer
Install and Configure TigerVNC server on Ubuntu 18.04 18.10

Install Gnome 3 or 4 desktop

Type the following command to install Ubuntu Linux desktop:
$ sudo apt install ubuntu-gnome-desktop
$ sudo systemctl enable gdm
$ sudo systemctl start gdm

How to configuring the VNC service

Login to user account, say vivek:
$ su - vivek

A sysadmin can create a new VNC user account too for the new desktop user using the useradd command and passwd command. For example, create a VNC user account nixcraft that will need to access the system via VNC:
$ sudo useradd nixcraft
$ sudo passwd nixcraft

Next setup a password for vnc login:
$ vncpasswd
$ ls -l ~/.vnc/

reate a vncpassword

How to configuring Gnome 3 Desktop environment to use with VNC

You need to create a file name ~/.vnc/xstartup using a text editor such as vim command or nano command:
$ vi ~/.vnc/xstartup
Append the following:

#!/bin/sh
# Start Gnome 3 Desktop 
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &

How to start TigerVNC server

Type the following command to start the vnc server on Ubuntu:
$ vncserver
One can setup desktop bit depth such as 8, 16, 24, 32 and Desktop geometry in {width}x{height} as follows:
$ vncserver -depth {8|16|24|32} -geometry {width}x{height}
$ vncserver -depth 32 -geometry 1680x1050

Verify it with the ss command and pgrep command/egrep command:
$ pgrep Xtigervnc
$ ss -tulpn | egrep -i 'vnc|590'

Start vncserver

How to stop TigetVNC server

To klill a VNC server running at desktop at :1
$ vncserver -kill :1
Here is what we see on the terminal window:

Killing Xtigervnc process ID 9523... success!

VNC server to kill all, instances (*) of TigerVNC, run:
$ vncserver -kill :*

How to list VNC server sessions on Ubuntu Linux

Pass the -list option as follows to the vnserver:
$ vncserver -list
Sample outputs:

TigerVNC server sessions:

X DISPLAY #	RFB PORT #	PROCESS ID
:1		5901		9523

Note down the port # 5901. We are going to use that one with the ssh command.

How to connecting with a VNC client and ssh session

Prerequisite
By default, remmina command may not be installed on your system. Hence, use the apk command on Alpine Linux, dnf command/yum command on RHEL & co, apt command/apt-get command on Debian, Ubuntu & co, zypper command on SUSE/OpenSUSE, pacman command on Arch Linux to install the remmina.
VNC is a clear text and insecure network protocol. To make the communication secure, you must encrypt your server-client connection by using an SSH tunnel between the VNC server and the client. Type the following ssh command to setup SSH tunnel from your Linux or Unix desktop:
$ ssh user@remote-server -L 5901:127.0.0.1:5901
$ ssh vivek@power9 -L 5901:127.0.0.1:5901

Open a local vnc client named remmina and type url 127.0.0.1:5901
Connecting with a VNC client
Once connected you can see the desktop:

Conclusion

You just learned how to install and configure TigerVNC server on Ubuntu 18.04 LTS or 18.10. You need to make the communication secure using ssh. Finally, you connected to VNC server using SSH tunnel. For more info see TigerVNC home pager here.

Did you find this article useful?