How to install a VNC server on Linux

If you need to remote into a GUI-enabled Linux server, your fastest, cheapest option is VNC.

How to install a VNC server on Linux If you need to remote into a GUI-enabled Linux server, your fastest, cheapest option is VNC. Jack Wallen shows you how.

There are instances when you need to not only log into a remote Linux machine but gain access to the full desktop of said machine. When you need to do such a thing, you're going to need the help of a VNC server.

Fortunately, setting up such a server isn't challenging and can be done without spending a single penny on software. I'm going to walk you through the process of installing and configuring a VNC server with the help of the Ubuntu Server, version 18.04.

SEE: Server deployment/migration checklist (Tech Pro Research)

What you need

In order to successfully get this up and running, you need the following:

  • Ubuntu Server 18.04.
  • User with sudo privileges.
  • VNC Client to connect to the remote machine.

With the requirements met, let's make this happen.

Installing a desktop

We need to have a desktop on our Ubuntu server. For this, we'll install the lightweight Xfce desktop (since we'll be running it remotely). To do this, log into your Ubuntu Server instance and issue the command:

sudo apt-get install xfce4 xfce4-goodies -y

Installing the VNC server

We're going to use TightVNC for this purpose. It's fairly easy to get up and running and reliable. To install this particular VNC server, open a terminal window on the machine you wish to use remotely and issue the command:

sudo apt-get install tightvncserver -y

Upon the completion of the installation, issue the command:


This will create the initial VNC configuration. You will be required to create passwords (which cannot be longer than eight characters) for both login and view-only access (Figure A). The view-only access password is optional.

Figure A

Figure A: Configuring the VNC server on first run.

When this step completes, you should see reported there is a new 'X' desktop running (Figure B) at USERNAME:1 (where HOSTNAME is the hostname of the remote machine).

Figure B

Figure B: Our VNC desktop is available.

Now kill the VNC server with the command:

vncserver -kill :1

Configure the VNC server

Before restarting the VNC server, you'll want to create a new configuration file. Run the command:

nano ~/.vnc/xstartup

In this file, paste the following contents:

xrdb $HOME/.Xresources
startxfce4 &

Save and close that file. Change the execution permissions of the file with the command:

sudo chmod +x ~/.vnc/xstartup

Restart the VNC server with the command:


You should now see reported that the new 'X' desktop is at HOSTNAME:1 (where HOSTNAME is the hostname of the remote server).

Connecting to the server

We're going to use SSH tunneling to the server (for a secure connection). I'll connect to the remote Linux server using a local Linux machine. On the local desktop create the SSH tunnel with the command:

ssh -L 5901: -C -N -l USER SERVER_IP

where USER is the remote username used to start and configure the VNC server, and SERVER_IP is the IP address of the remote server. You will be prompted for the remote user's password. Once that authenticates, the secure tunnel is running (you won't get the prompt back).

Start your VNC client tool and enter localhost:5901 as the address for the VNC server. Once connected, you'll be prompted to enter the VNC password you created. Upon successful authentication, you should see the remote desktop (Figure C).

Figure C

Figure C: Our remote desktop for the Ubuntu Server.

When you're finished with the connection, close out your client application, and kill the SSH tunnel by typing the [Ctrl]+[C] keyboard combination in the terminal window. If you want to reconnect to the remote VNC server, you'll need to re-create the SSH tunnel before connecting with your client.

Ready to remote

And that is all there is to setting up a VNC server on Linux. When you need to be able to remote into a server, and use a GUI desktop, this might be your best option—at least when you want it up and running fast and on the cheap.

Also see

Image: Jack Wallen

By Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website