Install and Configure TigerVNC server on Ubuntu 18.04

last updated in Categories , ,

How do I install and configure TigerVNC server on Ubuntu 18.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 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 LTS Linux based system to get access to full Gnome 3 desktop.

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 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 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

$ 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 TigerVNC server

To lill a VNC server running at desktop at :1
$ vncserver -kill :1
Sample outputs:

Killing Xtigervnc process ID 9523... success!

VNC server to kill all, *
$ vncserver -kill :*

How to list VNC server sessions on Ubuntu Linux

$ 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

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 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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Join the discussion at www.nixcraft.com