Raspberry Pi Zero–VNC Server/Client Setup

Installing VNC

SSH (see http://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh/overview) is often all you need to control your Raspberry Pi, however sometimes it is useful to be able to remote control your Raspberry Pi using the mouse and seeing just what you would see on the screen of the Raspberry Pi. 

VNC (Virtual Network Connection) is a standard for doing just this. To use it, you have to install some software on your Pi. There are a number of VNC server applications, and the one we are going to use is called “tightvnc”.

We can install the VNC server software using the SSH connection that we established earlier.

Enter the following command into your SSH terminal:

Copy Code

  1. sudo apt-get update
  2. sudo apt-get install tightvncserver


You will be prompted to confirm installation by typing “Y’ and finally when installation is complete, you should see the following:


We now need to run the VNC Server, so enter the following command into your SSH window:

Copy Code

  1. vncserver :1


You will be prompted to enter and confirm a password. It would make sense to use “raspberry” for this, but passwords are limited to 8 characters, so I use “raspberr”. Note that this is the password that you will need to use to connect to the Raspberry Pi remotely.

You will also be asked if you want to create a separate “read-only” password – say no.

From now on, the only command that you need to type within your SSH to start the VNC server will be:

Copy Code

  1. vncserver :1

The VNC server is now running and so we can attempt to connect to it, but first we must switch to the computer from which we want to control the Pi and setup a VNC client to connect to the Pi.

Using a VNC Client

Again, there are many VNC clients, of which “VNCViewer” (http://www.realvnc.com) is available for most platforms and I have found it to work well with TightVNC.

When you first run VNCViewer, you will see the following:


Enter the IP address of your Raspberry Pi, append :1 (to indicate the port) and click on “Connect”. You will then get a warning message. Just click ‘Continue’.


The following window will then popup for you to enter your password (“raspberr”).


Finally, the VNC window itself should appear. You will be able to use the mouse and do everything as if you were using the Pi’s keyboard mouse and monitor, except through your other computer.

As with SSH, since this is working over your network, your Pi could be situated anywhere, as long as it is connected to your network.


Built in Screen Sharing

There’s also a built in VNC app for the Mac OS X that you may be able to use without installing any software
From the Finder, select Go -> Connect to Server… and typevnc:// (or whatever the IP is) to connect.

Running VNCServer at Startup

This method will only work if you have set your Pi to automatically log into the desktop environment. See Lesson 2.

Connecting to your Raspberry Pi remotely with VNC is fine as long as your Pi does not reboot. If it does, then you either have to connect with SSH and restart the VNC Server or arrange for the VNC Server to run automatically after the Raspberry Pi reboots.

There are several different methods of arranging for some code to be run as the Pi starts. The method described below is probably the easiest to use. You can adapt it to run other commands instead of starting the VNC server.

Step 1.

Open a Terminal session on the Pi, or connect using SSH. A new terminal or SSH session will automatically start you off in your home directory of /home/pi. If you are not in this directory, change to it by typing:

Copy Code

  1. $ cd /home/pi

Then cd to the .config directory by typing:

Copy Code

  1. $ cd .config

Note the ‘.’ at the start of the folder name. This makes it a hidden folder that will not show up when you type ‘ls’.

Step 2.

Issue the command below to create a new directory inside .config called ‘autostart’.

Copy Code

  1. $ mkdir autostart

cd into that new directory by typing:

Copy Code

  1. $ cd autostart


Step 3.

All that remains is to edit a new configuration file. So type the following command to open the nano editor on the new file:

Copy Code

  1. $ nano tightvnc.desktop

Edit the contents of the file with the following text.

Copy Code

  1. [Desktop Entry]
  2. Type=Application
  3. Name=TightVNC
  4. Exec=vncserver :1
  5. StartupNotify=false


Type ctrl-X and then Y to save the changes to the file.

Thats all there is to it. The next time you reboot the VNC server will restart automatically.

Source – https://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc/installing-vnc

Thanks to Simon Monk.

Happy Coding Smile

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s