How To Install and Configure TigerVNC server on Ubuntu

See all Ubuntu Linux related FAQ
How do I install and configure TigerVNC server on Ubuntu 18.04/20.04/22.04/24.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/24.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/24.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/18.10/20.04/22.04/24.04 LTS

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:
# -----
# create a new user named nixcraft with
# /home/nixcraft as home dir (-m)
# /bin/bash shell (-s)
# -----

vivek@wks01:~$ sudo useradd -m -s /bin/bash nixcraft
vivek@wks01:~$ sudo passwd nixcraft

You can login as nixcraft user using the su command/runuser command/sudo command. For example:
vivek@wks01:~$ su - nixcraft
Password:
nixcraft@wks01:~$

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

You can only allow connections from the same machine. Useful if you use SSH and want to stop non-SSH connections from any other hosts. For example:
$ vncserver -localhost -geometry 800x600 -depth 32
Verify it with the ss command and pgrep command/egrep command:
$ pgrep Xtigervnc
$ ss -tulpn | grep -E -i 'vnc|590'

Start vncserver

How to stop TigetVNC server

To kill a VNC server running at desktop at :1, type:
$ 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 :*
The -kill option will kill and stop your TigetVNC server.

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/20.04/22.04/24.04 LTS or 23.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. See the following manual pages using the man command or help command:
$ man vncserver

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

18 comments… add one
  • GNT :) May 25, 2024 @ 8:59

    You are a person after my own heart. Thanks for the technical help.

    Working on Jammy 18.04 LTS TigerVNC. I got it working on my
    Jammy 20.04 64 bit server now working with 32 bit Jammy.
    Canonical was talking about doing away with 32 bit support.
    Not a good idea with all of the 32 bit servers out there and people like
    you and I. Thanks :)

Leave a Reply

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

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.