How to enable SSH on Raspberry Pi
Connect to the Raspberry Pi using SSH
How to connect to the Raspberry Pi using SSH
From Windows
If you use Microsoft Windows on your primary computer, note that there are no tools for SSH connections installed by default.
That's why you'll have to download and install an app, like Putty. Putty is one of the most used software to use SSH on Windows.
Download files that match your computer's specifications. Depending on the version selected, install it or not, then launch Putty.
Putty looks like this:
Putty interface
To login enter the IP address in the Host Name field and click Open.
The default SSH credentials are:
- Login: pi
- Password: raspberry
If things are not working now, don't worry, the article will explain what to do later.
From Linux or Mac
If you use a Unix-based system i.e. any Linux distribution, or even macOS, you'll have to use the command 'ssh' to connect from a terminal.
Sometimes you need to install SSH, for example on a Debian-based distribution:
sudo apt-get update sudo apt-get install ssh
The command to connect to the Raspberry Pi will look like this:
ssh pi@IP
Replace the IP with the IP address of the Raspberry Pi.
How to enable SSH on Raspberry Pi
From the desktop
For security reasons, SSH is not enabled by default on the Raspberry Pi. You have to enable it yourself by going to Start menu > Preferences> Raspberry Pi Configuration .
Go to the Interfaces tab and enable SSH.
Go to the Interfaces tab and enable SSH
From a terminal
Similarly from the terminal, you will also have to manually start SSH.
To do this, enter the following command:
sudo service ssh start
You can also check the service status by typing:
sudo service ssh status
How to automatically start SSH when booting
You will quickly find that SSH, even when enabled, will not start up automatically. So you have to find a way to force it to launch.
There are several ways to do this. We have chosen to add a cron for root to launch SSH every time:
Step 1. Edit root crontab like this:
sudo crontab -e
Step 2. Add this line to the end of the file:
@reboot /usr/sbin/service ssh start
If you haven't understood this yet, don't hesitate to read our guide on how to schedule tasks on your Raspberry Pi.
IP address and port to connect
By default, SSH starts on port 22.
Therefore, you must connect to the Raspberry Pi's IP pointing to port 22.
Example from Linux:
ssh pi@192.168.1.200
Or if you have changed the SSH port, specify the port with the -p option :
ssh pi@192.168.1.200 -p2222
Replace 2222 with the selected port.
How to connect SSH without password
Now you know how to enable SSH on Raspberry Pi and how to connect to it. But if you have to do it regularly, typing in your password every time will quickly become boring.
There is a way to create an SSH key that identifies you in place of the user's password. This article will explain how to set up this key according to your operating system.
Of course, the password connection will still be possible, if you forget the key or use another computer.
From Windows
First things first, on Windows you will need the full Putty toolkit, with PuttyGen and PuttyAgent. So if you've just downloaded the SSH client to the portable version, you have to install all the rest.
You will also need a tool to transfer files to your Raspberry Pi. WinSCP is a good choice, worth considering.
Then follow these steps:
Step 1. Create SSH keys with PuttyGen:
- Launch PuttyGen.
- Select RSA as the key type.
- Enter 4096 as the number of bits.
- Click Generate.
- Leave all other options as default, no passphrases.
- Save the key where you want.
Step 2. Transfer public key to Raspberry Pi using WinSCP:
- Add a new location with Raspberry Pi login and IP information.
- Connect with this location.
- On the left side, go to the folder where you saved your key.
- On the right side, go to the / home / pi directory.
- Transfer public key to Raspberry (drag and drop).
Step 3. Allow this key to work on Raspberry Pi:
- Connect to Raspberry Pi using Putty.
- Add the transferred public keys to the allowed keys:
cat /home/pi/you_key.pub >> ~/.ssh/authorized_keys
- Close Putty.
Step 4. Try to reconnect with Putty.
- This step does not require you to enter a password and log in directly.
- If you still need to log in, enter pi @ IP in the Hostname field (replace the IP with the IP address of the Raspberry Pi).
From Linux or Mac
Step 1. If not, create the SSH key with the following command:
ssh-keygen -t rsa
Just click Enter
for each question, default path and no password required.
Step 2. Copy the public key file to the Raspberry Pi:
cp ~/.ssh/id_rsa.pub pi@IP:/home/pi/your_key.pub
Replace IP with Raspberry Pi IP address, name the key as you like.
Step 3. Add this key to the keys allowed to operate on the Raspberry Pi with the command:
cat /home/pi/you_key.pub >> ~/.ssh/authorized_keys
Step 4. Try connecting again:
ssh pi@IP
You do not need to enter a password and can log in directly.
You should read it
- How to enable DNS over HTTPS for all apps in Windows 10
- Steps to enable TPM 2.0 to install WINdows 11
- How to Enable JavaScript
- Activate foreign keys in SQL Server
- How to Enable JavaScript on a Mac
- How to enable Dark Mode in Notepad on Windows 10/11
- How to Enable Incognito Mode
- How to enable Spatial Sound in Windows 11
- How to Enable USB Booting on a Chromebook
- How to Enable YouTube Comments
- Open the Excel file and show Enable Editing and something you don't know
- Steps to enable Enhance Audio to improve sound quality on Windows 11