Install and Configure VNC Server on Ubuntu Linux

|

|

This tutorial guides on installing the Virtual Network Computing (VNC) server on Ubuntu 16.04 or 18.04, which allows remote connections using the VNC protocol. It explains how to install a light desktop environment, ‘Xfce’, before installing the VNC server, specifically ‘TigerVNC’. The tutorial also covers initial setup, VNC server configuration, and checking its status.

This brief tutorial shows students and new users how to install a Virtual Network Computing (VNC) server on Ubuntu 16.04 | 18.04 servers to allow remote connection via VNC protocol.

VNC is a graphical desktop sharing system that allows users to connect remotely to a system with keyboard and mouse access. This is an open-source alternative to Microsoft Remote Desktop Protocol.

When you’re ready to get started with installing and configuring the VNC server on Ubuntu, follow the steps below:

Install Desktop Environment

Ubuntu servers don’t have a desktop environment by default, and VNC requires the desktop environment to function.

Since we don’t want to install a full-blown desktop environment, a lightweight Xfce environment is a better alternative.

To install Xfce, run the commands below

sudo apt update
sudo apt install xfce4 xfce4-goodies xorg dbus-x11 x11-xserver-utils

Install VNC Server

Now that a lightweight desktop environment is installed run the commands below to install the VNC server. Many VNC servers are available, including TightVNC, x11vnc, and TigerVNC.

For this post, we will be using TigerVNC. To install TigerVNC, run the commands below:

sudo apt install tigervnc-standalone-server tigervnc-common

After installing TigerVNC, run the commands below to set up an initial setup, including creating a password to access the desktops.

vncserver

That should output a similar message as below:

You will require a password to access your desktops.

Password:
Verify:
Would you like to enter a view-only password (y/n)? n

New 'ubuntu1804:1 (richrd)' desktop at :1 on machine ubuntu1804

Starting applications specified in /etc/X11/Xvnc-session
Log file is /home/richrd/.vnc/ubuntu1804:1.log

Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/richrd/.vnc/passwd :1 to connect to the VNC server.

vncserver: Failed command '/etc/X11/Xvnc-session': 256!

=================== tail -15 /home/richrd/.vnc/ubuntu1804:1.log ===================
Starting applications specified in /etc/X11/Xvnc-session has failed.
Maybe try something simple first, e.g.,
    tigervncserver -xstartup /usr/bin/xterm

Afterward, the server command will create a password file and store it in your ~/.vnc folder.

Configure VNC Server

Once the VNC server is installed, run the commands below to configure it.

vncserver -kill :1

Then, create a startup-config file.

nano ~/.vnc/xstartup

Add the lines into the file and save.

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4

Run the commands below after the above.

chmod u+x ~/.vnc/xstartup

Next, create a systemd file.

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

Then, add the lines below to the file and save.

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
User=richard
PAMName=login
PIDFile=/home/%u/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver :%i -geometry 1440x900 -alwaysshared -fg
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

After saving the file, run the commands below to reload the systemd config.

sudo systemctl daemon-reload

Start and enable the VNC server.

sudo systemctl start vncserver@1.service
sudo systemctl enable vncserver@1.service

I checked to see if VNC is started and running.

sudo systemctl status vncserver@1.service

You should see something similar to the one below.

● vncserver@1.service - Remote desktop service (VNC)
   Loaded: loaded (/etc/systemd/system/vncserver@.service; indirect; vendor preset: enabled)
   Active: active (running) since Mon 2019-02-04 15:22:07 CST; 17s ago
 Main PID: 14025 (vncserver)
    Tasks: 0 (limit: 4663)
   CGroup: /system.slice/system-vncserver.slice/vncserver@1.service
           ‣ 14025 /usr/bin/perl /usr/bin/vncserver :1 -geometry 1440x900 -alwaysshared -fg

Feb 04 15:22:06 ubuntu1804 systemd[1]: Starting Remote desktop service (VNC).

Now you’re all set. Find a VNC client and attempt to access the server.

A good VNC to use is the VNC Viewer from RealVNC. Install it and connect it to the server.

server_name:5901

Type in the password you created above and connected

Enjoy!

Congratulations! You’ve successfully installed, configured, and connected to a VNC server on Ubuntu 16.04 | 18.04

You may also like the post below:


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



One response to “Install and Configure VNC Server on Ubuntu Linux”

  1. masonbee Avatar
    masonbee

    Everything went well until the end when the VNC viewer errored with “The connection was refused by the computer”, I tried KRDC in VNC mode and the same thing happened, ufw Status:inactive, any ideas?

Leave a Reply to masonbeeCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading