Establish a VNC Connection to a Remote Ubuntu Server

by Saahyl

VNC is called Virtual Network Computing. Its VNC that makes it possible for us to control some other (remote) computer over a network connection.
In this blog we will be learning how we can control and perform actions on a remote server from our local machine.

  1. SSH enabled remote machine (ubuntu server),
  2. GUI enabled remote server,
  3. Display manager installed on the remote server,
  4. VNC server installed on the remote server and
  5. A VNC client or viewer on the local machine.

We would first login into the remote server using SSH. At the remote server, as servers do not come with GUI enabled operating system we require to install a GUI.
There are many GUI variants available to us varying from the lightest(lower memory consumption) to full fledged(high memory utilisation). It is always recommended to install a lighter variant and go with installation of software packages as you need them. Some of the GUI variants available are:
1. Minimal Gnome Core Desktop (lightest)
For full install use command – “sudo apt-get install ubuntu-gnome-desktop”.
To install the lighter version without any basic software packages installed,
use command –
“sudo apt-get install xorg gnome-core gnome-system-tools gnome-app-install”.

2. Lubuntu or LXDE Desktop
For full install use command – “sudo apt-get install lubuntu-desktop”
For lighter version,
use command – “sudo apt-get install –no-install-recommends lubuntu-desktop“.

3. Unity Based Ubuntu Server GUI
For full install use command – “sudo apt-get install ubuntu-desktop”.
For lighter version,
use command – “sudo apt-get install –no-install-recommends ubuntu-desktop”.
If you are going to do any system administration work and require to work regularly on the remote server then I would suggest you to use the lighter version of the GUI’s since more software packages make your system vulnerable to hacks. I required to work on the remote server for sometime to test a few browser cases,so I used the full version Unity Ubuntu Desktop.

After installing a GUI on remote server we need to have our display manager up and running. Lightdm is the default display manager for most of the GUI variants while sometimes the above installation may ask you to choose a display manager, select “lightdm”, as it is a lightweight alternative to the previously used “GDM”. If there is no display manager installed, you can install it using the following commands,
“sudo apt-get update”
“sudo apt-get install lightdm-gtk-greeter”
“sudo reboot”
To be sure of whether the display manager is running, start it using the command- “sudo service lightdm start”

A display manager is responsible for starting a display server. Sometimes referred to as a “login manager”, the display manager is responsible for providing us with a login screen or “greeter” when we start it for the first time and also loads the linux desktop soon after we login.

Having successfully installed the GUI and display manager on the remote server we now have to install a VNC server on the remote ubuntu server. I used the X11 VNC server, to install this use command – “sudo apt-get install x11vnc”.

We now have a GUI enabled remote server, Display manager installed on the remote server, VNC server installed on the remote server. It’s time to install a VNC client on the local client machine. I used a simple VNC client called the Gtk VNC Viewer, you can install this from your Ubuntu Software Center.
After installing the VNC client SSH again into the remote server and start the VNC server there. Use the command – “x11vnc -display :0” to start the VNC server.
If the above command fails to start the server with error message – “XOpenDisplay(“:0”) failed”, then try using the command – “x11vnc -forever -httpdir /usr/share/vnc-java -noxdamage -httpport 5900 -auth /var/run/lightdm/root/:0 -display :0”.
If the problem starting x11vnc server persists try restarting your display manager and run the command shown below to get the correct path of the display manager used to start VNC server,
After successfully starting the VNC server the terminal output should have something like this in the end,
* Note down the port no. the server has used. The default port for VNC server is 5900, but if you have some process already running on that port or an instance of VNC previously started has no released the port yet, the VNC server may use another available port as you can see in my case it started on 5901. The terminal would not return the prompt so keep it running….

We now go to our local machine and start the VNC client from the ubuntu dash, the Gtk VNC Viewer we installed earlier.
Enter the credentials and connect, after successful connection a login screen will display for the first run of the display manager on the remote server,
Select the Guest Account and choose the GUI to load from the options in the dropdown. I used the Ubuntu variant because I installed the full fledged variant of it earlier. After login you’ll get the remote server’s Ubuntu desktop.
* To free up memory on the server after you are done with troubleshooting or administration work use ctrl+c to send close signal to VNC server and use command – “stop lightdm” to stop the display manager but before recreating the VNC connection the next time, you’ll have to start the display manager using “start lightdm” command.
Now you have control over the remote server sitting at your place.
Cheers Admin!! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Tools & Practices

Tools and Technologies we use at Applied

Contact us now

Popular Posts