Remote Raspberry Pi Access - VNC

Remote Raspberry Pi Access - VNC

What is Remote Access?RealVNC

'Remote Access' is a way of accessing one computer from the other.  There are a few different ways to do this.  The most basic is from the 'command line', where all you can see is text in a window and you can only type into that window.  Another way is to view the Graphical User Interface (GUI) of the 'remote' computer.

In both cases you need a 'server' on the computer you want to access, and a 'viewer' on the computer you are using.

In this tutorial we are going to be looking at VNC, which is a cross-platform piece of software, which means it can run on a PC, Mac, Raspberry Pi, Android, IOS or Linux computers.  VNC is free and open-source, so it will cost you nothing to use unless you want more advanced features.



One of the best VNC products from a company called RealVNC. They were founded by the inventors of VNC, and have made it available recently for the Raspberry Pi.  While the basic VNC software is free, there are some additional features that require the purchase of a license, like encryption of the information between the server and viewer, better performance and support.

As mentioned above, there are two parts to the Remote Access software; the Server, which will run on the Raspberry Pi and serve the screen view to other computers, and the Viewer, which you use on other computers to view what is being shown by the server.

Installing RealVNC on the Raspberry Pi

To install the RealVNC on the Raspberry Pi, turn on your Raspberry Pi and type the following into a terminal window:

curl -L -o VNC.tar.gz https://www.realvnc.com/download/binary/latest/debian/arm/

The 'curl' command downloads the contents of a URL to your PC.  Here, curl is getting the latest RealVNC software version from the RealVNC website.

The next command will extract the viewer and server software from the file you have just downloaded above:

tar xvf VNC.tar.gz

As the files are extracted you will see the Server and Viewer software file names listed.  You will need these in the next step, which is to install the software.  If you want to just view the screen of your Raspberry Pi on another computer you only need to install the Server software.  If you want to use the Raspberry Pi to view the screen of another computer, then install the Viewer software.  We are just going to install the Server software here.

To install the Server software, type the following into the terminal window, replacing the name of the file with the one listed when you extracted the software:

sudo dpkg -i VNC-Server-5.2.3-Linux-ARM.deb

Before you can use RealVNC Server you must obtain a license key.  They are free for private use, and can be obtained from the RealVNC license page.  Once you have filled in the form you will see the license key, and it will be emailed to you.  Use it to license your software by typing in the following on your Raspberry Pi:

sudo vnclicense -add <license-key>

Where <license-key> is the license key you obtained above.

Installing RealVNC on the Viewing Computer

To make use of VNC you will need Viewer software on another computer.  How you install that software depends on what sort of computer you have.  You can download a suitable viewer from the RealVNC website.

Running the RealVNC Server

Back on the Raspberry Pi you need to start the VNC Server.  You need to first make sure you are in Desktop mode (with the mouse and menus) before starting the VNC Server.  If you are not, type 'startx' to start it up.

There are two ways of running the server on the Raspberry Pi; Service mode and Virtual mode.  With Service Mode you will see exactly what is on the Raspberry Pi's screen.  With Virtual mode it is like running another separate computer on your Raspberry Pi - the current user will not be able to see what you are doing.

We are just going to use Service Mode.  You can read more about Virtual Mode from the RealVNC instruction page.

First, you must create a new VNC password so that you can log into the VNC server.  In a terminal window type the following:

sudo vncpasswd /root/.vnc/config.d/vncserver-x11

You will be prompted to enter the same password twice.  This is the password that you need to use in the Viewer to access your Raspberry Pi.

Now you can start the VNC server.  Note that you must already have the Raspberry Pi in Desktop mode - otherwise it will not know what to display in the Viewer!

sudo /etc/init.d/vncserver-x11-serviced start

You can set VNC to start every time you start your Raspberry Pi using the following:

sudo update-rc.d vncserver-x11-serviced defaults

Remember that your Raspberry Pi needs to be running in Desktop mode, so you should use the raspi-config command and Enable Boot to Desktop.

Remotely Accessing your Raspberry Pi

You should now be able to access your Raspberry Pi remotely from another computer.  Start the VNC viewer on the other computer and enter the IP address of your Raspberry Pi (you can find it from the terminal window on your Raspberry Pi by typing ifconfig).

VNC Viewer

If the connection is made successfully then your Raspberry Pi's screen will appear on your computer, and you will be able to control it just as though you were using the Raspberry Pi's own keyboard and mouse:

VNC Viewer

What Next?

You can of course continue to use RealVNC for free, forever!  Within your own network at home this is okay and safe, but if you want to be able to access your Raspberry Pi over the internet, then you will need to use encryption to ensure that nobody else is able to intercept what you are seeing.  For this you will need to obtain a 'Personal' license from RealVNC.  This costs only £19 and is for life too, but well worth it if you want to use encryption, better performance, sharing printers and file transfer.  To obtain the license, visit the RealVNC website.

Leave a comment

All comments are moderated before being published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.