How to remote control your Raspberry Pi
World-wide Pi
Using your Raspberry Pi is normally accomplished via a keyboard, mouse and monitor but at times this might be awkward, for example when controlling a robot or time-lapse photography rig.
Remotely controlling a computer is nothing new but it's a handy solution to accessing your hard to reach Raspberry Pi project.
In this Raspberry Pi project we'll install an SSH server, which will enable us to remotely control the Raspberry Pi using the terminal from another machine.
We'll also install a VNC server which will enable us to use the Raspberry Pi desktop over a network.
- Find out what else you can do with the tiny PC with our collection of Raspberry Pi Projects
Getting started
Connect up your Raspberry Pi and boot Raspbian to the desktop, you may need to log in using your username and password.
If your Raspberry Pi doesn't boot straight to the desktop type startx in LXTerminal and press Enter. If you're using a Wi-Fi dongle, make sure that it's configured and has an IP address.
If you're using an Ethernet connection, open LXTerminal and type ifconfig to find your IP address.
Are you a pro? Subscribe to our newsletter
Sign up to the TechRadar Pro newsletter to get all the top news, opinion, features and guidance your business needs to succeed!
Now we must configure the software that will run on the Raspberry Pi and give us the access that we need. Open LXTerminal and type the following to setup an SSH server:
sudo raspi-config
Navigate to the Advanced Options Menu and look for SSH server, enable it and exit the application. If you're asked to reboot, do so and return to the desktop.
With the SSH server installed we can now test that it works using another computer. We're using a laptop running Linux Mint and SSH'd into the Raspberry Pi using the terminal:
ssh pi@IP OF YOUR PI
The first time that you connect to the Raspberry Pi, SSH will ask you to confirm that the Raspberry Pi is what you think it is via a unique fingerprint, and for this project we can accept that it's correct.
After a few moments you will be asked for your Raspberry Pi password and need to successfully log into your Raspberry Pi.
Any command issued from this point onwards will be run on the Raspberry Pi.
Remote control your Raspberry Pi
With the SSH server successfully installed, our attention shifts to installing the VNC server. In the SSH session run the following command:
sudo apt-get install tightvncserver
This installs the VNC server and to run the server type:
tightvncserver
You'll be asked for a password – use a strong one with a maximum of eight characters. You will also be asked for a view-only password that isn't needed at this time.
In the terminal you'll see the output of the tightvncserver command, and it will advise you that a VNC session has been started and that you can connect using the IP address or hostname followed by :1.
Now we need a VNC client on our computer to connect to the server running on the Raspberry Pi. We've used Vinagre which comes installed on Linux Mint and Ubuntu.
Open Vinagre and click on Connect, in the host box enter the IP address of your Raspberry Pi, followed by :1 and click Connect. You will be asked for your VNC password. With the correct password entered you can now use your computer's mouse and keyboard to control your Raspberry Pi and the Raspbian desktop is visible on your desktop.
For those of you looking to play Minecraft in this manner, we're sorry to say that, at this time, it's not possible due to the way Minecraft renders itself on the Raspberry Pi. Generally though, you're now able to use your Pi remotely from another computer in your home.
In fact, you can have more than one VNC connection running, which will enable two people to share a Raspberry Pi.
What's SSH and VNC?
SSH is used by system administrators to remotely work with servers across the world, for instance, a VPS or server running a website or web application. Because there's no physical access to the device a user has to remote in using SSH either via a terminal, or using a web interface provided by a host.
SSH connections are encrypted and it's highly unlikely that anyone can see what's being done, unlike VNC which should not be used over the internet. VNC sends its information via an unencrypted connection and any VNC ports that are open can be scanned by malicious parties.
In fact, there's a website that lists websites with open VNC ports and enables you to connect just like Chat Roulette. However, tunnelling a VNC connection via SSH, grants you a level of security.
There are SSH applications for all OSes and on Linux it comes by default, and VNC applications are installed with Ubuntu and Linux Mint in the form of Vinagre.
- Enjoyed this article? Expand your knowledge of Linux, get more from your code, and discover the latest open source developments inside Linux Format. Read our sampler today and take advantage of the offer inside.