How to setup a VNC (Virtual Network Computing) Server running on a Ubuntu Desktop (Linux)

Client running VNC Software with the Server (Computer you want to control) running X11VNC

The prerequisites:

  • A Windows or Linux client computer running VNC client software like RealVNC, TightVNC etc. We will call it “Client”.
  • A computer running any flavour of Linux with the X Window system such as Ubuntu 14.04/16.04 Desktop, Red Hat or Mint Destkops. We will call it the “Server”.

Install the software X11VNC on the Server :

sudo apt-get install x11vnc -y

This installs the x11vnc server software

Lets add a password to secure the server to unauthorized access :

sudo x11vnc -storepasswd /etc/vncpwd

This command will prompt you to enter a new password and re-enter for verification. After that it will store the password in the file vncpwd at the location /etc/vncpwd in an encrypted format.

We store it in /etc so that in the next few steps when we create a service for x11vnc, the service is able to access the password file from /etc/vncpwd where it automatically has access during startup (boot)

Lets test the setup once…

Open a terminal window on the server you want to control and enter :

sudo x11vnc -rfbauth /etc/vncpwd -auth guess -rfbport 5901

The above command will run the vnc server on the Linux system and start listening for connections at port 5901. The password will be picked from the file vncpwd.

Try connecting through another computer :

Open up Remmina client on Ubuntu or RealVNC Connect client and add the details to create a new connection. You will need to know :

  • The IP address of the computer which is running x11vnc
  • A user-name and password on the computer which is running x11vnc so that you are able to login from the client computer.
Remmina Client Settings

If all goes as planned you should be able to connect to the client !

But wait, this connects me to new session each time, how do I connect to the existing running session on the Linux system ?

Its simple, remember that in Linux the display are numbered from :0, :1, :2 ?

Linux systems use the :0 to signify the first display :1 the second display and so on. x11vnc provides us with a command line option to allow x11vnc to run on DISPLAY :0 meaning the current display on the system. This is inherently useful in situations when you do not want to create a new session each time you log-on and just want to re-use the current session on the system you want to control.

Yup its quite simple…

Its also useful when you have a an application which is running for extended periods e.g (data mining) and would like to check back on the system from time to time to see the results.

So in this case the command will look like this

sudo x11vnc -rfbauth /etc/vncpwd -auth guess -rfbport 5901 -display :0

Alright, lets create a service on the Linux system to run x11vnc on startup

Create the service unit file :

Open the terminal window on the system running x11vnc and enter the following commands :

sudo nano /lib/systemd/system/x11vnc.service

Copy Paste the following lines in the editor opened in terminal. CTRL + X , and Y to save the file.

Description=Start x11vnc at startup.

ExecStart=/usr/bin/x11vnc -viewonly -display :0 -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.pass -rfbport 5900 -shared


Enable the service to run on startup

sudo systemctl enable x11vnc.service
sudo systemctl daemon-reload

Reboot the system

sudo systemctl -i reboot

And thats it ! You now have x11vnc running on the Linux system at all times and can connect as per your convenience.

Related posts

Leave a Comment