How to Use VNC to Access a Remote Linux Server

VNC (Virtual Network Computing) provides a convenient and efficient method for remotely accessing and controlling servers, offering a graphical interface that simplifies administrative tasks and supports collaboration. This article will show you how to install VNC Server on Linux and connect to the remote Linux Server.

Steps to Use VNC to Access a Remote Linux Server


You already get the server login credentials
Once your server is deployed, the login credentials are usually sent to your registered email. You can also get server login information, including username, password, and port in the Database Mart control panel, please refer to guide on how to manage servers in Database Mart control panel.

1. Install desktop environment on the Remote Linux Server

In this tutorial, we will use the Ubuntu 20 operating system. As Ubuntu servers don't have a desktop environment by default, and VNC requires the desktop environment to function. Therefore, we will install a desktop environment first. Xfce is a popular desktop environment choice for being lightweight and fast.

Please refer to the guide How to Connect to a Linux Server Remotely to log in to your Remote Linux Server. Next, input your login password as prompted.

As the following several operations require the root permission, we will switch to the root user first using the command below.

sudo -i
Switch to the root user by running command sudo -i

After that, issue the commands below to update your list of packages, followed by installing Xfce and the xfce4-goodies pacakge, which includes additional software and artwork that are related to the Xfce desktop.

apt update
apt install xfce4 xfce4-goodies
Run apt update
Install Xfce

Before the installation, you are often prompted to confirm the disk space this operation will use. Input "y" to continue the installation.

Confirm Xfce installation

During the installation, you will be prompted to choose a default display manager - gdm3 or Lightdm - for Xfce. Choose either one and press enter to continue.

Introduction to display manager
Choose a default display manager

2. Install VNC on the Remote Linux Server

For the VNC software, we will install TightVNC.

After the Xfce installation, install the VNC server - TightVNC by running the following command.

apt install tightvncserver

Next, run vncserver to start a VNC (Virtual Network Computing) desktop. You will be required to set a VNC access password then. Specify your password twice as prompted and press enter.

Run vncserver command

You are given another option for set a view-only password for VNC access after the above step. As the name suggests, it is a password that allows the user to only view the remote screen and restrict mouse and keyboard input from clients who authenticated with the view-only password. The view-only password is not required. If you need one, type "y" and create a password. Otherwise, hit "n" and press enter.

Set view-only password

If you need to change your password or add a view-only password later, you can run the following command.

Reset the password of VNC access

3. Configure the VNC Server

This step will configure which graphical desktop environment the VNC server should connect to when it starts up.

First, stop the running VNC server instance.

vncserver -kill :1
Stop running VNC server instance

Next, we will modify the configuration file called "xstartup." Before this step, it's recommended to back up the original configuration file.

mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
Run vncserver command

Then, use your prefered editor to modify the "xstartup" configuration file. Here we use the nano editor.

nano ~/.vnc/xstartup
Use nano editor to modify configuration file

Add the following lines to the file.

xrdb $HOME/.Xresources
startxfce4 &
Edit the xstartup configuration file

Use the "chmod" command to change the perssion of the file and make it executable.

chmod +x ~/.vnc/xstartup
Edit the xstartup configuration file

After that, restart the VNC server.

vncserver -localhost
Restart the VNC server

4. Install VNC viewer on your local computer

Now you need to install a VNC viewer on the device where you would like to initiate the connection. This is so that you can connect to the remote server from you local devices. In this instance, we use a Windows desktop.

Search for VNC viewer in the browser and click into the site. Here, we use the Real VNC as an example.

Search VNC Viewer in the browser

Choose Windows desktop and click Donwload VNC Viewer.

Download VNC viewer

Once the file is downloaded, double-click it to start the installation. First, select the language you would like to use during the installation and click OK. Then, click Next to start the installation process.

Choose VNC Viewer language
Click Next to continue with the viewer setup

Read the license agreement carefully and check to accept the terms, followed by clicking Next.

Accept the terms in the License Agreement of VNC Viewer

In the Custom Setup window, choose the feature you'd like to install and customize the location where you prefer to keep the file. Then click next to continue.

Select the way you want features to be installed

In this window, click Install to begin the VNC Viewer installation.

Click Install to begin the VNC Viewer installation
VNC Viewer setup finishes

5. Connect to the VNC Desktop Securely

By default, VNC does not utilize secure protocols for communication. To enhance the security of your VNC connection, it is recommended to establish an SSH tunnel before connecting. In this example, we are using PuTTy to connect to the Linux server and create an SSH tunnel by right-clicking on the top of the terminal windows, followed by clicking Change Settings...

Right click the top of th terminal window and then click Change Settings

In the left panel of the PuTTy Reconfiguration windows, go to Connection > SSH > Tunnels. Configure the Source port 59000, and Destination as localhost:5901, then click Add and Apply.

Configure SSH tunnel for VNC connection

Once the tunnel is running, use a VNC client to connect to localhost:59000.

Connect to localhost:59000

You will be prompted to input the VNC access password, which you have set in step 2.

Input VNC access password

Once the password passes the authentication, you will see the default Xfce desktop as follows.

Successful VNC access

You can now control your remote Linux server via VNC

Control your remote desktop via VNC