Installing VNC server in Raspberry Pi running Raspbian

This guide assumes you already have Raspbian OS installed in your Raspberry Pi. VNC is very useful when we intend to manage our Raspberry Pi remotely. This means we don’t need a separate display, keyboard and mouse. Just leave Raspberry Pi on and connected to local network, and we can remotely access it from other computer with VNC client.

raspbian-desktopBefore installing new application or service in Raspbian, make sure to always type this into terminal :
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

If you’re installation is not the latest version, it might take a while as Raspbian will download the latest files from Internet. My Raspbian image file is dated 9 Feb 2013. Different version of Raspbian might produce different behavior.

Now, open terminal again and type:
sudo apt-get install tightvncserver
This will install TightVNC into Raspbian system.

Next, we need to do first-time run to set the password. Type this into terminal:
tightvncserver :1
Then enter your desired password (8 characters) for VNC connection.

Having VNC executed with user action does not serve the purpose of preparing Raspberry Pi for remote access. We need to add VNC server into startup sequence. There are more than one ways to do this, but I’ll use an easy one.

As usual, type this into terminal:
wget http://www.robertsetiadi.com/download/tightvncserver-init.txt
sudo mv tightvncserver-init.txt /etc/init.d/tightvncserver

Credit to PenguinTutor for the script. You may need to change the variable on line 16. It is currently set to pi (the default username on the Raspbian OS image). Set this to whatever username you want to login to TightVNC as, but do not put root as the user.

sudo chown root:root /etc/init.d/tightvncserver
This is to change the ownership of the file (set to belong to root).

sudo chmod 755 /etc/init.d/tightvncserver
This is to make the file executable.

sudo update-rc.d tightvncserver defaults
This is to add the script to startup.

Just for additional information, you can manually start VNC by:
sudo /etc/init.d/tightvncserver start or sudo /etc/init.d/tightvncserver stop

Now you need to know the IP address of your Raspberry Pi.
ifconfig eth0 (if you’re using network cable)
ifconfig wlan0 (if you’re using WiFi)

Finding MAC address: (this command is actually not needed for VNC)
cat /sys/class/net/eth0/address (if you’re using network cable)
cat /sys/class/net/wlan0/address (if you’re using WiFi)

You might also want to make your Raspberry Pi having a static IP address:
sudo nano /etc/network/interfaces

Then change this line:
iface eth0 inet dhcp
into:
iface eth0 inet static
and add the following lines below the iface line:
address 192.168.1.8 (change this with your desired address for the Pi)
netmask 255.255.255.0
network 192.168.1.1
broadcast 192.168.1.255
gateway 192.168.1.254
Of course, you should adjust the lines according to your network settings.

The next step is to install VNC client in another computer and test the connection. This will depend on which operating system it uses and which VNC client you prefer. For the connection, you will need Raspberry Pi’s IP address and port. For the port, try 1 or 5901. I am using Chicken VNC in Mac and can connect without any problem.

Lastly, a quick tip. In VNC mode, I was unable to shutdown my Raspberry Pi using GUI. The only option available is “Log Out”. Type this into terminal to perform manual shutdown:
sudo shutdown -hP now

 

Also read: my other posts about Raspberry Pi

 

By | 2014-09-05T16:13:19+00:00 11 Apr 2013|Guide, Technology|1 Comment

One Comment

  1. Omar Butt 13 May 2013 at 11:22 pm - Reply

    Hi,
    Great tutorial. Worked like a charm after trying several links on google. If I can ask you for a bit of help, I need to go ahead a step further which will allow me to run a powerpoint slide show using libreoffice. The command line for that is:

    root@:# soffice -show Sign.ppt.

    What do I need to do to get this command to launch at startup and to open automatically at startup. I’m quite a noob at this so Please try to make it simple just like your tutorial above.

    Many Thanks,

Leave A Comment