Learn how to use SSH to remote control your Raspberry Pi
ⓘ This article may have been partially or fully translated using automatic tools. We apologize for any errors this may cause.
For the past year and a half we have had the blog Raspbian France, we have had the opportunity to receive numerous emails from users asking questions on very diverse subjects.
Among all these questions, knowing how to take control of the Raspberry Pi remotely comes back very frequently!
So, you bought and installed your Raspberry Pi (if you have not already done so, what are you waiting for?), but you do not have a screen and you want to control it from your computer? Do not panic, we’ll help you!
What is SSH ?
Before seeing how to control the Raspberry Pi with SSH, let’s see exactly what SSH is.
SSH was created in 1995 with the main aim of allowing the remote control of a machine through a command line interface.
SSH (for Secure SHell) refers to both, computer software and communication protocol. This protocol also has the peculiarity of being fully encrypted. This means that all the commands you execute via SSH will be completely secret!
Today, SSH is mainly used through the free OpenSSH implementation that is present in most Linux distributions.
How does SSH work?
We will not go into cryptographic and other details here. We’ll just take a quick look at how you can use SSH.
In general, SSH allows to connect remotely on a machine using a user account of the said machine.
To do this, the computer that needs to connect to the remote machine will provide the computer with the name of the user to use and its password. It is possible in certain cases to use a set of certificates on the computer and the remote machine, thus making it possible to obtain a secure connection without having to type a password. This is a case of more extensive use that we will not either discuss here.
By default SSH offers only a command line takeover. It is possible in some cases to add a graphical interface but this is a more complex method than we will not see here.
Install SSH to remotly control of your Raspberry Pi
Now that we know a little more about SSH, let’s see how to set it up to control your Raspberry Pi!
First, you should know that the installation of SSH is split into two parts. Indeed, you will need one side of an SSH server on your Raspberry Pi and another one of an SSH client on your computer. The first will receive the commands to launch while the second will send them.
Enable the SSH server on your Raspberry Pi
By default, SSH is installed on the Raspberry Pi, but is disabled for security reasons. The first thing to do will therefore be to enable SSH on your Raspberry Pi.
To do this, simply plug the MicroSD card of your Raspberry Pi into your computer, go to the card, and create a file named ssh in the
Once done, all you have to do is put your SD card back into your Raspberry Pi, and SSH will be activated the next time you start it.
Note that now that SSH is enabled, any account created on your Raspberry Pi can be used to connect via SSH. So make sure to use strong passwords (including changing the default password of the
Install the SSH client on your computer
A priori, this time you do not have an SSH client installed on your computer, so you will have to install it yourself.
So there are two possibilities (actually three, but if you have a Mac you will have to do it yourself):
- Either you have a Windows computer (and we wonder why: b)
- Or you have a Linux computer (And women – or men for that matter – throw themselves at your feet, your enemies fear you and your friends envy you).
So we will see bot cases, how to install SSH client for Windows and how to install SSH client for Linux.
How to install an SSH client on Linux
If you are on Linux, you already know, the world is more beautiful! To install an SSH client, nothing more simple, you just need to run the following command:
sudo apt-get update && sudo apt-get install openssh-client
The first part of the commande (before the “&&”) will tell to the system to update the list of the packages (the software library if you prefer). The second part, her, will ask to the system for installing the SSH client.
You see, everything is simpler under Linux (yes, we are in bad faith)!!
How to install an SSH client on Windows
You made the wrong choice but it will be much forgiving (well maybe) …
You will have to install the software Putty which is an SSH and TelNet (some old and insecure but sometime handy protocol) client. You can find this excellent tool on the dedicated website.
Interestingly, Putty is part of this software that does not require installation, so you only need to download it !
Use SSH to connect to the Raspberry Pi
Now that we have installed a server and an SSH client, all we have to do is use them.
Here again, two different methods depending on whether you are under Linux (blessed be the great penguin) or Windows (that breaks its tiles).
Basically, the principle remains the same, use the SSH client to communicate with the server (here your Raspberry Pi), using the server address, a user name and the associated password.
Use SSH with Linux
As always with Linux, all you need is a single command line to connect to the Raspberry Pi.
Of course, you will have to replace
user with the name of the user with whom you want to connect and
server_ip_or_url by the server IP this URL if it has one.
Once you have entered the user account password (which, for security reasons, usualy not appear when you type it), you will be connected to the Raspberry Pi terminal and all commands will be run on the Raspberry Pi!
To exit SSH simply use the command
Use SSH with Windows and Putty
For Windows, as often, it will have to go through the GUI. You will have to launch Putty and fill in the information as in the image below.
ip_address with the IP address or URL of the server.
For information, the port number (22) is the default SSH port.
Once done, click on the “Open” button. A console window should open by asking you the username you want to use and then its password. Once done, you will be connected to the Raspberry Pi.
Like Linux, you just have to type
exit to leave the connection.
Note that it is possible to save SSH configurations with Putty. If you want to use this function, we can advise you not to save the password, this being really a bad practice in terms of security!
So, you now know how to control your Raspberry Pi remotely with SSH!
All you have to do is install your cloud at home! And if you prefer to use a good old screen and a keyboard, go for a ride on our article on accessories!