Install VNC server

Go to End

Note

8/12/2024: Created.

Intro

VNC server enables remote access to the graphical desktop of Ubuntu server.

There are different VNC server packages: x11vnc, Tight VNC server, Tiger VNC server, etc.

x11vnc is described on a different page.

Set router

Set the internet router to permit access to the server through ports 5900, 5901, 5902, etc.

Disable Wayland

Ubuntu-desktop uses gdm3 (Wayland) display manager. Wayland is not compatible with VNC servers.

Execute to disable Wayland:

$ sudo gedit /etc/gdm3/custom.conf

Remove "#" to uncomment the following line:

#WaylandEnable=false

Reboot the computer.

Install VNC server

Log in an account on the server directly or via a SSH client such as Putty installed as https://kctang.com.hk/web/install-openssh-services.

Execute:

$ sudo apt install tigervnc-standalone-server
or
$ sudo apt install tightvncserver
$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n

The password will be stored in the file ~/.vnc/passwd, i.e. home/<current user>/.vnc/passwd.

Execute to create a file:

$ nano startvnc.sh

to contain:

#!/bin/bash
vncserver -kill :2
vncserver :2 -xstartup /usr/bin/gnome-session-classic -geometry 1600x900 -localhost -alwaysshared 

vncserver -kill :2 = kill any existing VNC server at port 5902

vncserver :2 = start a new VNC server at port 5902

-xstartup /usr/bin/gnome-session-classic = use gnome-session-classic as the server desktop

-geometry 1600x900 = screen size 1600x900

-localhost = permit access via a SSH tunnel from a remote client computer or mobile phone that the user is using, and not permit access via internet browser

-alwaysshared = permit sharing the server desktop with other remote computers or mobile phones

The server desktop will not be seen on the server itself. It is a virtual desktop accessible to other remote computers or mobile phones. This is a called "headless" server.

The VNC server will stay until it is killed by command: vncserver -kill :2

Execute to start the vncserver:

$ ./startvnc.sh

Start again after server reboot.

Set up SSH tunnel via Putty

Putty has been used for OpenSSH as https://kctang.com.hk/web/install-openssh-services.

Configure a SSH tunnel by entering the Source port and Destination as follows, then press Add to move the setting to the upper window:

With "Local" selected, the Source port means the port of the client computer. It can be "5900" or any free port, e.g. 5902 in this case. "Localhost:5902" at the Destination means the server computer, not the client computer. "5902" refers to the port number on the server computer providing VNC server service.

Go back to the first screen, highlight Default Settings and press Save again.

Log in to the same user account used to start the VNC server.

Install VNC viewer

Download and install a VNC viewer app on the local computer.

There are many VNC viewer apps, such as:

RealVNC at: https://www.realvnc.com/en/connect/download/vnc/

UltraVNC at: https://uvnc.com/downloads/ultravnc.html

There are also mobile phone apps. The setting is similar.

For RealVNC Viewer, after installation, select File > New connection to show:

For VNC Server, enter:

kctang.com.hk: 5902 

for access via an internet browser where the server port is set to 5902, or

localhost: 5902

for use when "-localhost" is included in the start server file, for access via a SSH tunnel from the remote device to the server where the server port is set to 5902. This is more secure.

Press OK to save as an icon:

Click the icon to open the password screen, and enter the password previously set for the server:

The server screen will appear.

End of Page

Back to top with progress scrollbar