Learn how to use SSH to remote control your Raspberry Pi
CommentairesFor 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 boot
partition.
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 pi
user)!
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.
ssh user@server_ip_or_url
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 exit
.
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.
Again, replace 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!
Conclusion
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!
Hi,
I’m little confused as currently I can’t see anything on my Pi and am trying to connect via SSH to resolve the issue. How do I know what the IP Address is for the host name? You mention for the server? Is this my laptop or is this the Pi itself? If it’s the laptop, is this my public IP or my private IP?
How will the Pi connect to my laptop if I haven’t set up the wifi?
Thanks,
Ollie
Hello, the ip address if the private ip adresse of the pi.
You can probably find it in your router administration page, or by using the netstat tool on a computer connected to the same network than the pi.
In order for your laptop to connect with the pi you need to have both connected to the same network. You can connect your Pi to the network by taking a look to our tutorial to run a headless pi.
It looks like this article isn’t fully edited, there are typo’s in a few places and there are plain French paragraphs before their translated versions in the end.
Oh, thanks, i will fix that.