Sunday, 9 February 2014

How to VNC into a Headless RaspberryPi

Much has been written about using VNC with a headless RaspberryPi, but I seem to struggle with some of the suggested methods.

I also generally prefer to use the VNC server "x11vnc", as I like to view the same session as one open by a local user.

So here are my notes...

Configure RaspberryPi

Install x11vnc, either using Synaptic or simply from a terminal like this:-

sudo apt-get install x11vnc

Create an auto-launcher by writing a text file with these lines:-

[Desktop Entry]
Exec=x11vnc -forever -display :0


...and save the file as x11VNC.desktop in this location: /home/pi/.config/autostart/

Note: the file name extension ".desktop" is important, otherwise this launcher will not appear in "Desktop Session Settings" list.  In a rather Windows Explorer like fashion, the LXDE file manager (pcManFM) does not show the .desktop extension, but if you use "ls" in terminal you can confirm that the file name & extension are correct.

Reboot the Pi and then go to:-

 start menu > Preferences > Desktop Session Settings

...and enable x11VNC

Note: I had a frustrating issue on one RaspberryPi where the x11VNC option did not show up in Desktop Session Settings list. This turned out to be because I had a backup of x11VNC.desktop file which was auto created by my editor (in this case gEdit). It seems that with both x11VNC.desktop and x11VNC.desktop~ files in the autostart folder, LXSession was getting confused. Deleting the backup (~) file seems to fix it.

So now, booting the Pi will automatically start the x11vnc server.

The VNC Client

To VNC into the RaspberryPi from my Lubuntu laptop I use vncviewer by typing into a terminal:-


...where the IP number is obviously the one allocated to the Pi.

Image Issues

Great, but there are a couple of problems. First of all, the VNC image on my laptop is a bit small. I'd quite like it to fill the screen on my laptop.

Secondly, it only shows a small part of the RaspberryPi desktop. There is something terribly wrong with the resolution.

The image size can be increased by editing the VNC launcher on the RaspberryPi. As the resolution on my laptop is 1366 x 768, I need to specify this with the "geometry" option.

[Desktop Entry]
Exec=x11vnc -forever -geometry 1366x768 -display :0

For the second problem, the RaspberryPi /boot/config.txt file must be edited (as root) to include:-


Now the VNC image is more useful...

...and the image can be switched to full-screen from a pop-up menu by pressing F8, so that the local task-bar is hidden by the remote (RaspberryPi) task-bar.


  1. Hi Steve,
    Thanks for the blog about using the RPI remotely. I have it working within my internal network great. Now I would like to access my pi from outside so I need to set up my router for port forwarding. Does x11vnc use a particular port? Thanks!

    1. The default port for vnc is 5900. If this port is already in use, vnc will increment until it finds one free.

      On a Linux box you can type: man x11vnc ...but this can be difficult to read as there are a fantastic number of command options.

      Take a look at this excellent site:

      You will probably want to use Secure SHell (as discussed on that site) when using vnc across the net.

      Good luck.

    2. Thanks for the great information! I changed my port forwarding to 5900 and I installed on my windows machines and on my Android phone and can gain access to my pi anywhere.