RPi VNC Server

From eLinux.org
Revision as of 11:54, 10 September 2012 by The Captain (Talk | contribs) (How does it work?)

Jump to: navigation, search

Back to RPi Guides.

Raspberry Pi VNC Server

What does it do?

Sometimes it is not convenient to work directly on the raspberry pi. Maybe you would like to work on it but from another computer by remote control. You can do this and the remote computer can even be anywhere in the world over the internet. This tutorial shows how you can view and control the raspberry pi desktop from your computer's desktop by using special software.

What do you need?

  • A Raspberry Pi, model B.
  • A boot SD card for the Raspberry Pi.
  • A network connection (Ethernet or WiFi).
  • Special software on both the Raspberry Pi and the remote, controlling computer

What skill level is required?

This project does not require any coding or compilation. Very basic Linux and networking knowledge would be useful, but not essential.

You need to...

  • Install software
  • Enter basic Linux commands
  • Use standard software tools (Windows/Linux/Mac) to add software to your PC
  • Connect computers using ethernet cables

How does it work?

The commands described below start a "virtual" graphical session. Instead of using a hardware framebuffer, this uses RAM for a framebuffer. It also opens a network channel or port that allows programs on other computers (if they provide the password) to show the framebuffer and provide mouse and keyboard events.

This way you can run a desktop session on the raspberry pi, but display and control it elsewhere.

Because the framebuffer isn't the real framebuffer you cannot take advantage of the GPU to accelerate operations on the screen.

Overview of this project

You need to

  • Install a VNC server on the Raspberry Pi
  • Start the VNC server
  • Install a VNC client on another computer


Log in to your Pi and install the Tight VNC Package

$ sudo apt-get install tightvncserver

Next Run TightVNC Server which will prompt you to enter a Password and an optional View Only Password

$ tightvncserver

Once that is done you can run it straight from the prompt I am using 1920x1080 which is my monitor maximum resolution.

$ vncserver :1 -geometry 1920x1080 -depth 24

Or you could create a script to save typing in the whole thing.

$ nano svnc.sh (call the file whatever you like)

Add the lines:

vncserver :1 -geometry 1920x1080 -depth 24

Ctrl-x y <return> (To Exit Nano and Save)

Set the file to Execute

$ chmod +x svnc.sh

then to run

$ ./svnc.sh

Run at boot.

Start a root session

sudo bash

Create a file in /etc/init.d with a suitable name such as vncboot with the following content.

# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.

#! /bin/sh
# /etc/init.d/vncboot


export USER HOME

case "$1" in
   echo "Starting VNC Server"
   #Insert your favoured settings for a VNC session
   /usr/bin/vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565

   echo "Stopping VNC Server"
   /usr/bin/vncserver -kill :1

   echo "Usage: /etc/init.d/vncboot {start|stop}"
   exit 1

exit 0

Modify the file permissions so it can be executed

chmod 755 /etc/init.d/vncboot

Enable dependency based boot sequencing

update-rc.d /etc/init.d/vncboot defaults

If enabling dependency based boot sequencing was successful, it says

 update-rc.d: using dependency based boot sequencing

But if it says

update-rc.d: error: unable to read /etc/init.d//etc/init.d/vncboot

then try the following command

update-rc.d vncboot defaults

Reboot your Raspberry PI and you should find a vncserver already started.

Install Tight VNC on your desktop from the link below or most VNC clients work I believe.


Or install it using your package manager. The following works on my ubuntu 11.10 workstation

sudo apt-get install xtightvncviewer

Then use <Your Pi IP>:1 (e.g. as the host name when connecting.[1]

Works Great, select full screen from the tool bar and a full 1080p 24bit desktop is yours from anywhere.

  1. You can put your raspberry pi in /etc/hosts on Linux systems. I think you can make such a file on windows too. Then you can refer to your raspberry pi as "rpi" or whatever you called it.

Getting VNC Server to Work on a Specific User

Instead of using the script in the Raspberry Pi wiki, use this one provided by "Penguin Tutors":

# /etc/init.d/tightvncserver
# Customised by Stewart Watkiss
# Set the VNCUSER variable to the name of the user to start tightvncserver under
case "$1" in
   su $VNCUSER -c '/usr/bin/tightvncserver :1'
   echo "Starting TightVNC server for $VNCUSER "
   pkill Xtightvnc
   echo "Tightvncserver stopped"
   echo "Usage: /etc/init.d/tightvncserver {start|stop}"
   exit 1
exit 0

Now, change the VNCUSER=pi to your desired username, so for example: VNCUSER=jsmith

That'll make it boot on the username of which you want it to boot on... but I then received the grey screen error when remotely accessing the Pi from my computer, now the way you fix this is, open up the xstartup file that was created when VNCSERVER executes on your desired username. Now the way you access it and edit it is by:

sudo nano .vnc/xstartup 

.vnc is usually in the home directory.

Delete everything that is in xstartup (or not in as mine was), and add this:

xrdb $HOME/.Xresources
xsetroot -solid black
/usr/bin/lxsession -s LXDE &

Now it should work.

Does Your Openbox Configuration Settings Not Start on VNC?

You'll often find yourself in a position where VNC will start, but you'll get things such as multiple virtual desktops appearing, and you try to save it in the "Openbox Configuration Manager," and they go away for a second, but then you find you'll restart the Pi and then they appear again. Here's how to fix it:

Create, or edit the current autostart.sh file which is located in:


Edit using "Nano" or any other text editor, I use Nano as it is the most comfortable for me, so do:

sudo nano .config/openbox/autostart.sh/

Add the line: exec openbox-session

Now add the line exec openbox-session again in .vnc/xstartup and now it should work.

But you can't really save the setting in Openbox Configuration Manager on VNC, but you have to do it manually; so you open this file:

nano .config/openbox/lxde-rc.xml

Scroll down to: <desktops>

You should see a bunch of stuff there, but only focus on this: <number>6</number> or something similar.

Change the number of desktops you want within the <number></number> bit.

I changed mine to 1, because that's all I want.

It should now work!