How to install and configure a VNC server in Ubuntu 16.04 LTS

VNC or Virtual Network Computing is a graphical desktop sharing tool that allows you to remotely control a computer (server) from another computer (client). The VNC server transmits all keyboard and mouse events from the client computer to the server computer. If you are not familiar with command line interfaces such as a terminal, etc., you can use VNC to simplify the management of files, software, and system settings.

In this guide, we will walk you through the steps of setting up a VNC server in Ubuntu 16.04. We install Linux Desktop XFCE on the server, then install and configure the VNC server using TightVNC.

Background

  • Ubuntu 16.04
  • Root privileges

What will we do

  1. System Update and User Creation
  2. Install XFCE Desktop and TightVNC
  3. Initial VNC Configuration
  4. Customize TightVNC
  5. Launch TightVNC as a service
  6. Connect to a VNC server through an SSH tunnel

Step 1 – System Upgrade and User Creation

Update your Ubuntu repository, then update your system using the apt commands below.

sudo apt update sudo apt update

For this guide, the VNC desktop will be accessible to the non-root user. So, we need to create a new user and add him to the sudo group for root access.

Create a new user named “edward” and give him a password.

useradd -m -s / bin / bash edward passwd edward

Now add the user “edward” to the sudo group to access root privileges.

usermod -a -G sudo edward

A new user has been created with the name “edward” to access the VNC, and the user will be able to access the root privileges.

soo – edward sudo soo

Step 2 – Install XFCE Desktop and TightVNC

Linux has several desktop environments such as Gnome, Unity, KDE, LXDE, XFCE, etc. In this tutorial, we will use the XFCE desktop as the VNC desktop environment.

Install the XFCE desktop, including all dependencies, using the apt command below.

sudo apt install xfce4 xfce4-goodies

If the installation of XFCE on the desktop is complete, install the silentvncserver packages.

Run the apt command below.

sudo apt install -yightvncserver

The XFCE desktop and silentvncserver were installed on the Ubuntu 16.04 server.

Step 3 – Initial VNC Setup

At this point, we will generate the VNC configuration for the edward user.

Login as “Edward”

su edward

Now run the vnc configuration for the user “edward” using the command below.

Vncserver

You will be prompted to enter the VNC server password – enter your password. And for a “view-only” password, you can enable or disable it. A user who logs on to the server with a “view-only” password cannot control the mouse and keyboard.

Launch VNC Server

When you run the vncserver command for the first time, it will automatically create a new .vnc configuration directory and start the first VNC session.

Check it out with the command below.

ls -lah ~ / .vnc / ps -ef | grep Xtightvnc

And you will get the result as shown below.

VNC server is working correctly

Step 4 – Configure TightVNC

At this point, we will configure the VNC server to use the XFCE desktop. We will edit the VNC configuration file “xstartup” in the “.vnc” directory.

Before editing the configuration, end the first VNC session using the command below.

vncserver -kill: 1

Now back up the default configuration and create a new one using pressure,

mv ~ / .vnc / xstartup ~ / .vnc / xstartup.bekup vim ~ / .vnc / xstartup

Insert the following configuration there.

#!/bin/bash
 xrdb $HOME/.Xresources
 startxfce4 &

Save and exit.

Now make the script executable with chmod and run the vncserver command again.

chmod + x ~ / .vnc / xstartup vncserver

Check out the list of sessions.

ps -ef | grep Xtightvnc

And you will get the result as shown below.

How to check and kill a VNC session

Step 5 – Launch TightVNC as a Service

In this tutorial, we will start the VNC server as a service. Therefore, we need to create a new utility file for it.

Go to the directory “/ etc / systemd / system” and create a new service file[email protected]”.

cd / etc / systemd / system vim [email protected]

Paste the following vnc service script there.

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

[Service]
  Type=forking
  User=edward
  PIDFile=/home/edward/.vnc/%H:%i.pid
  ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
  ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
  ExecStop=/usr/bin/vncserver -kill :%i

[Install]
  WantedBy=multi-user.target

Save the file and exit the editor.

Now restart the systemd services and start the VNC server service.

systemctl daemon reboot systemctl startup [email protected]

Assuming everything goes without errors, add the service at boot time and check the status of the service using systemctl.

systemctl enable [email protected] systemctl status [email protected]

Below are the results in our case:

VNC as a service

The VNC server is installed, and the first session is now running as “edward”.

Step 6. Connect to the VNC server through the SSH tunnel.

At this point, we will connect to our VNC server through an ssh tunnel.

Open your terminal and enter the ssh command as shown below.

ssh -L 5901: 127.0.0.1: 5901 -N -f -l Edward 192.168.33.10

Enter your password to log in to SSH.

Connect to VNC via SSH Tunnel

The command will create a tunnel between your local host and the VNC server. Port 5901 on the local host will be redirected to the VNC server “192.168.33.10” on port 5901.

Now open the “vnc viewer” application, create a new connection and enter the VNC server address with the IP address 127.0.0.1 localhost and port 5901, as shown below.

Vnc viewer

Connect to the VNC server and you will be prompted to enter the VNC server password. Enter your password and click OK.

Connect to VNC Server

You will now get the XFCE desktop from your server.

Click the Use Default Configuration button for the first time and you will get the XFCE desktop with the default configuration.

VNC connection to the server desktop

Installing a VNC server using TightVNC on Ubuntu 16.04 completed successfully.

communication

How to install and configure a VNC server in Ubuntu 16.04 LTS

Sidebar