PiTunnel

How to remotely access the Desktop of your Raspberry Pi over the internet

VNC is a tool for accessing your Raspberry Pi graphical desktop remotely. Setting up VNC is really easy but it usually only gives you access from another computer that is on the same network as your Raspberry Pi.

In this article we will guide you through how to use PiTunnel to allow you to access a VNC remote desktop for your Raspberry Pi from anywhere in the world. We will do this by using the Custom Tunnels feature of PiTunnel. All your Raspberry Pi needs is an internet conection and PiTunnel will do the rest.


What is PiTunnel?

PiTunnel is a service for remotely accessing your Raspberry Pi, and the projects that you build on it. A Device Monitor and Remote Terminal is included, and you can also create your own Custom Tunnels to access services running on your Raspberry Pi.


Enabling VNC Server

The first step is to enable VNC server on your device. The easiest way to do this is as follows:

  1. Open a terminal on your Raspberry Pi or use the PiTunnel Remote Terminal.
  2. Enter the command sudo raspi-config
  3. Use the arrow keys to select Interfacing Options and press Enter.
  4. Use the arrow keys to select VNC and press Enter.
  5. You will be prompted to enable VNC Server. Select Yes and press Enter.
  6. Use the arrow keys to select Ok and then Finish, to return to the terminal.


Installing a VNC Viewer

You will need to install a VNC Viewer on your computer, so you can connect to you Raspberry Pi. There are a number of viewers available, but the easiest to set up is Real VNC Viewer. You can download Windows and Mac installers from here: https://www.realvnc.com/en/connect/download/viewer/


Testing your server over your local network

After you have installed a VNC Viewer, you should test that you can connect to your Raspberry Pi on your local network. You should do this before setting up the tunnel for remote access, to check that everything is installed correctly.

  1. Open Real VNC Viewer.
  2. Enter the address "raspberrypi.local:0", where "raspberrypi" is the hostname of your device, and press Enter.
    NOTE: Please make sure that your Raspberry Pi is not using the default password 'raspberry', so that your device is protected from unauthorized access.
  3. Enter the username and password for the raspberry pi login. For example username "pi" and password "raspberry", and press OK.
  4. The VNC session should start, and you should see your Raspberry Pi desktop.


Creating a tunnel to access VNC remotely

Once VNC is running, and it is accessible on your local network, you need to create a custom tunnel so that it can be accessed through pitunnel.com. A custom tunnel allows you to access your Raspberry Pi VNC through PiTunnel.com with an address like pitunnel.com:12345.

Custom tunnels are created by entering a command in your Raspberry Pi terminal:

pitunnel --port=5900 --name=vnc

In the above command, 5900 is the standard port number used for VNC. For most users, you should be able to enter the command exactly like that.

After you run the command, you will see the following output in your Raspberry Pi terminal:

$ pitunnel --port=5900 --name=vnc
Connected to Tunnel Server pitunnel.com, v1
Waiting for Client connection


Testing your tunnel

  1. Go to the Custom Tunnels page and find out the world-wide accessible address for your tunnel.
  2. Open Real VNC Viewer and enter the "Available At" address from PiTunnel.com into the address field.
  3. If you are asked about Duplicate VNC Server identify, press Continue.
  4. Enter the username and password for the raspberry pi login. For example username "pi" and password "raspberry", and press OK.
  5. The VNC session should start, and you should see your Raspberry Pi desktop.


Making your tunnel persistent

Once you have tested that your tunnel works, you will probably want to make it perisistent. This means that the tunnel will load automatically every time your Raspberry Pi powers on, and stay active even if you close the terminal window.

To make a tunnel persistent, add --persist to the end of the command line options:

$ pitunnel --port=5900 --name=vnc --persist
Created Persistent Tunnel

Current Persistent Tunnels:
+----+-------------------------------------------------------+
| ID | Command-Line Arguments                                |
+----+-------------------------------------------------------+
| 1  | --port=5900 --name=vnc                                |
+----+-------------------------------------------------------+

For more information about creating and removing peristent tunnels, please see the Persistent Tunnels section of the documentation.


Next: Remote SSH Sessions