Remotely Control the Raspberry Pi using VNC
Virtual Network Computing (VNC) is a graphical desktop sharing system that uses the Remote Frame Buffer protocol (RFB) to remotely control another computer. It transmits the keyboard and mouse events from one computer to another, relaying the graphical screen updates back in the other direction, over a network. VNC is platform-independent – a VNC viewer on one operating system may connect to a VNC server on the same or any other operating system. There are clients and servers for many GUI-based operating systems, including Java.
I will endeavour to explain how to install and use VNC with your raspberry Pi. This will allow you to see/use the Raspberry Pi’s graphical desktop remotely, using the mouse and keyboard as if you were sitting in front of your Pi.
Connecting to a Pi like this can save on desktop clutter, and the problem of having multiple keyboards and mice all over the place. It also means you can put your Pi somewhere else on the network, but still control it.
Generally SSH 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 keyboard, as if using the Raspberry Pi directly.
VNC (Virtual Network Connection) is the standard for achieving just this. To use it, you have to install a VNC Server on the Raspberry Pi. There are a number of VNC server applications available, and the one I choose to use is called “tightvnc”.
Installing the VNC Server:
You can install the VNC server software using a SSH connection, or by using the Raspberry Pi Directly.
Start by entering the following command into your SSH terminal:
sudo apt-get update
sudo apt-get install tightvncserver
You will be prompted to confirm the installation by typing “Y’, and finally when installation is complete, you should see the output below:
Now let’s start the VNC Server, by entering the following command into your SSH window:
You will be prompted to enter and confirm a password that is the password that you will need to use to connect to the Raspberry Pi remotely.. The passwords are limited to 8 characters, so I use “password”.
You will also be asked if you want to create a separate “read-only” password – say “no“.
The only command that you need to type within your SSH to start the VNC server will be:
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.
Running VNCServer at Startup:
This method will only work if you have set your Pi to automatically log into the desktop environment.
There are several different methods of arranging for some code to be run as the Pi starts. The method described here I think is the easiest to use. You can also adapt it to run other commands instead of only starting the VNC server.
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:
Then change to the .config directory by typing:
Note: the ‘.’ at the start of the folder name. This makes it a hidden folder that will not show up when you type ‘ls’.
Issue the command below to create a new directory inside .config called ‘autostart’.
change into the newly created directory “autostart” by typing:
All that remains is to edit a new configuration file. So type the following command to open the nano editor on the new file:
Add to the content of the file b the following text.
Type ctrl-X and then Y to save the changes to the file.
That’s all there is to it. The next time you reboot the Raspberry Pi the VNC Server will restart automatically.
Using the VNC Viewer:
Now that you have VNC server running, now we can attempt to connect to it, but first switch to the computer from which we want to control the Raspberry Pi and setup a VNC client to connect to the Raspberry Pi.
There are many VNC clients, of which “VNCViewer” is available for most platforms, and I have found it to work very well with TightVNC.
Download and install “VNCViewer”.
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 tick the box, and click ‘Continue’.
The following window will then pop-up for you to enter your password (“password”).
Finally, the VNC window itself should appear. From the VNC Viewer Window, you will be able to use the mouse and keyboard as if you were using the Raspberry Pi’s keyboard, mouse and monitor, but through your other computer.
As with using a SSH Client, since this is working over your network, the Raspberry Pi could be situated anywhere, as long as it is connected to your network.
And that’s it. Happy Baking!
Remotely Control the Raspberry Pi using VNC,