Setup VNC Server for Remote Access (Headless)



Most of this documentation was taken from here.

Installing TightVNC
We'll install TightVNC as our VNC software. If you haven't already, it's a good idea to update your package management tool by running This updates a huge list of software that can be installed or updated using the Advanced Package Tool (APT). We can now install TightVNC by issuing the command Just type "y" (no quotes) when it asks if you want to continue.

Testing the Installation and Running the VNC Server
You can run TightVNC for the first time by sending the command where the "geometry" and "depth" tags set the display format of the server window when viewed on another machine. If successful, the shell returns something like It's important to note the "1" here is the screen number, and the corresponding port is 5901. You can chose the screen number 2 by modifying the command to In this case, the port number is 5902. The port number and IP address (or host name) are required when using the TightVNC Viewer.

Start TightVNC Server on Boot
I found a lot of wrong ways to do this, but this worked for me. Create a new file in the init.d directory: Enter the following: 
 * 1) BEGIN INIT INFO
 * 2) Provides: tightvncserver
 * 3) Required-Start: $remote_fs $syslog
 * 4) Required-Stop: $remote_fs $syslog
 * 5) Default-Start: 2 3 4 5
 * 6) Default-Stop: 0 1 6
 * 7) Short-Description: Start Tight VNC Server at boot time
 * 8) Description: Start Tight VNC Server at boot time.
 * 9) END INIT INFO


 * 1) ! /bin/sh
 * 2) /etc/init.d/tightvncserver

USER=pi HOME=/home

export USER HOME

case "$1" in start) echo "Starting Tight VNC Server" /usr/bin/tightvncserver :1 -geometry 1024x768 -depth 24 ;; stop) echo "Stopping Tight VNC Server" /usr/bin/tightvncserver -kill :1 ;; echo "Usage: /etc/init.d/tightvncserver {start|stop}" exit 1 ;; esac
 * 1) Insert your favoured settings for a VNC session

exit 0

Give the startup script executable permission:

We can now start or stop the service manually. Make sure you do this at least once and add the password as before if asked: In order to add the script to the startup routine, finally send the following command: When the Pi reboots, if as long as the wireless settings are correct, you should be good to go headless!

Opening VNC View on Other Computer
You also have to download the TightVNC software on the viewer computer. I use Windows, and you can download the software here. You should have a start menu folder for TightVNC with a TightVNC Viewer program. You can use either the host name (which you set up after running raspi-config) or the IP address of the Pi (found by running ifconfig). Follow the IP/hostname with two colons and then the port number (5901 if you ran "tightvncserver :1 ..." or 5902 if you ran "tightvncserver :2 ...", etc.

BEWARE: When using host name (which is REALLY handy when using DNS), the DNS cache may need to be flushed if the host name does not resolve to the correct IP address. In Windows, at the command line, run

NOTE: If you get an error saying something like "No connection could be made because the target machine actively refused it", your firewall may be blocking the port. To fix this, you need to add an "Inbound" exception to allow the incoming TCP port (5901). See here for more instructions.





