Ubuntu

How to install VNC Server on Ubuntu

How to install VNC Server on Ubuntu

Previously, we have shown you how to install the VNC Server on CentOS (Click Here). Today we are going to cover the installation and configuration of the VNC Server on your Ubuntu machine.

Since VNC uses the client/server model, we need to deploy the VNC Server on an Ubuntu machine. To test the connection, we will use the VNC Client on a Windows machine.

Before starting the VNC Server installation, first you need to make sure that your Ubuntu is up-to-date using the following commands:

sudo apt update sudo apt upgrade

Installing VNC Server on Ubuntu

Step 1. For the VNC Server work correctly on your Ubuntu machine, we need to install a graphical desktop such as KDE, Gnome, XFCE, etc. For this tutorial, we will be using the XFCE desktop.

Use the following command to install the XFCE desktop package and other dependencies packages.

sudo apt install xfce4 xfce4-goodies

Install XFCE Graphical Desktop and Other Dependencies

Step 2. Install the VNC Server package, there are many VNC Server packages, and we will be using the 'tightvncserver' one.

Use the following command to install the 'tightvncserver' package.

sudo apt install -y tightvncserver

Install The VNC Server tightvncserver Package

Step 3. Now, let's start the VNC server using the following command.

vncserver

You will be asked to create a VNC server password, type and verify the password as you can see in the below screenshot.

Generate The VNC Server Configuration File

Step 4. Once you run the VNC server command, it will generate a VNC configuration directory located in your home directory. This VNC directory contains a VNC configuration file called 'xstartup' for the user who executed the command.

You can list the contents of the VNC configuration directory using the following command.

ls -lah ~/.vnc/

Check Created VNC Server Configuration File

Step 5. To check if the VNC server process is running.

ps -ef | grep Xtightvnc

VNC Server Running Successfully

Configure VNC Server On Ubuntu

Step 1. Before starting in configuring the VNC server, we need first to stop the currently running session.

vncserver -kill :1

Stop The VNC Server Session

Step 2. Backup the default VNC server configuration file.

mv ~/.vnc/xstartup ~/.vnc/xstartup.backup_file

Backup The VNC Server Configuration File

Step 3. Create a new VNC server configuration file.

vi ~/.vnc/xstartup

Create New VNC Configuration File

Step 4. Edit the new configuration file and add the below lines:

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

The VNC Configuration File

Step 5. Set permissions on the new configuration file to be executable.

chmod +x ~/.vnc/xstartup

Step 6. Run the VNC server command.

vncserver

Run The VNC Server Command

Configure VNC Server Service

Next, we are going to configure the VNC server to run as a system service. And to do so, we need to create a new VNC server service file.

Step 1. Create a VNC service file.

sudo vi /etc/systemd/system/[email protected]

Create The VNC Server Service File

Step 2. Add the below lines to the VNC service file.

[Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=forking User= PIDFile=/home//.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

But do not forget to replace each tag with your username like the below screenshot.

Edit The VNC Server Service File

Step 3. Reload the systemd services daemon for changes to take effect.

sudo systemctl daemon-reload

Reload Systemd Daemon

Step 4. Start the VNC server service.

sudo systemctl start [email protected]

Start The VNC Server Service

Step 5. Enable the VNC server service to start automatically with the system startup.

sudo systemctl enable [email protected]

Enable The VNC Server Service

Step 6. Finally, check the VNC server service status to make sure that everything is running normally with no errors.

sudo systemctl status [email protected]

Check The VNC Server Service Status

Now you have the VNC server installed, and its session is up and running.

Step 7. Get your VNC Server IP that will be used in the next section.

ifconfig

The VNC Server IP

If the previous command did not work, you could download the net-tools first then use the ifconfig command.

sudo apt install net-tools

Install The Net Tools Package

Test The VNC Server Connection From Windows

In this part of the tutorial, we will test the VNC server by trying to connect from a VNC client on a windows machine.

Since the VNC protocol is not encrypted, it will be exposed to packet sniffing. So it is highly recommended to create an SSH tunnel that will safely and securely forwards all your local machine. In this case, is the VNC client machine traffic on port 5901 to the VNC server on the same 5901 port.

Step 1. To set up the SSH tunneling on Windows, you need to have the PUTTY client. Open Putty and enter your VNC server IP in the hostname filed like the below screenshot.

Open Putty and Set Your VNC Server IP

Step 2. From the left panel -> Under Connection Menu-> Open SSH -> Press Tunnels.

Enter the port number in the Source port field and vnc_server_ip:port_number in the Destination field. Then press the Add button as the below screenshot.

Open Putty

Next, you can go back to the session page to save the previous settings. You will not need to perform the previous steps every time you will open the VNC server. Finally, press Open to establish a connection to the VNC server.

Step 3. Putty will ask you for the username and password of your Ubuntu machine.

Enter Your Ubuntu Username And Password

After you login you will get a screen like the below one:

SSH Tunnel Created

By that, you have established an SSH tunnel now move on to the next step.

Step 4. Now open your VNC viewer and connect to the VNC server at localhost:5901.

Open VNC Viewer

You can skip the encryption warning.

Skip The Encryption Warning

You will be required to enter your VNC server password.

Enter The VNC Server Password

Finally, you will be able to see your Ubuntu desktop.

The VNC Server Screen

Congratulations you have just connected to your Ubuntu machine remotely.

AppyMouse On-screen Trackpad and Mouse Pointer for Windows Tablets
Tablet users often miss the mouse pointer, especially when they are habitual to using the laptops. The touchscreen Smartphones and tablets come with m...
Middle mouse button not working in Windows 10
The middle mouse button helps you scroll through long webpages and screens with a lot of data. If that stops, well you will end up using the keyboard ...
How to change Left & Right mouse buttons on Windows 10 PC
It's quite a norm that all computer mouse devices are ergonomically designed for right-handed users. But there are mouse devices available which are s...