Connecting your Raspberry Pi to the World Wide Web
Learn how to securely access and control your Raspberry Pi remotely using SSH. This tutorial will walk you through the entire process step-by-step, from enabling SSH on your device to connecting via a …
Updated August 8, 2023
Learn how to securely access and control your Raspberry Pi remotely using SSH. This tutorial will walk you through the entire process step-by-step, from enabling SSH on your device to connecting via a command line interface or graphical tool like PuTTY.
SSH (Secure Shell) is a powerful tool that allows users to remotely access and control their Raspberry Pi devices over the internet. This can be particularly useful when you need to work on your Raspberry Pi while it’s not connected to a monitor or keyboard, or if you simply prefer to manage your device from a distance.
Enabling SSH on your Raspberry Pi
To enable SSH on your Raspberry Pi, follow these steps:
- Open the terminal on your Raspberry Pi by navigating to Menu > Accessories > Terminal (on Raspbian) or search for “Terminal” in the activities menu (on Ubuntu Mate).
- Type
sudo raspi-config
and hit Enter. - Navigate to the “Interfacing Options” menu using the arrow keys, press Enter to select it, then navigate to SSH and press Enter again.
- Choose “Yes” when prompted to enable or disable SSH. This will activate the SSH server on your Raspberry Pi.
- Select “Finish” to save the changes and exit the configuration utility.
Connecting via Command Line Interface (CLI) using PuTTY
PuTTY is a popular SSH client for Windows that allows you to connect to your Raspberry Pi remotely. Here’s how to do it:
- Download and install PuTTY on your computer if you haven’t already.
- Open PuTTY and enter the IP address or hostname of your Raspberry Pi in the “Host Name (or IP Address)” field.
- Under “Connection Type,” select “SSH.”
- Click “Open” to initiate the connection.
- If this is your first time connecting, a security alert will pop up. Click “Yes” to proceed.
- Enter the username and password for your Raspberry Pi (default is “pi” with password “raspberry”).
- You are now connected to your Raspberry Pi via SSH!
Connecting via Command Line Interface (CLI) using macOS or Linux Terminal
If you’re using a macOS or Linux system, you can connect to your Raspberry Pi remotely using the built-in terminal application. Follow these steps:
- Open the terminal on your computer and type
ssh pi@<your_raspberrypi_ip>
, replacing<your_raspberrypi_ip>
with the IP address or hostname of your Raspberry Pi. - Press Enter to initiate the connection.
- When prompted, enter the password for your Raspberry Pi (default is “raspberry”).
- You are now connected to your Raspberry Pi via SSH!
Securing Your Connection with SSH Keys
Using an SSH key instead of a password provides an additional layer of security when connecting to your Raspberry Pi remotely. Follow these steps to set up SSH keys:
- On your computer, generate a new SSH key pair by running
ssh-keygen -t rsa
in the terminal (Linux/macOS) or PuTTYgen (Windows). - Copy the contents of the public key file (
id_rsa.pub
for Linux/macOS,id_rsa.ppk
for Windows) to your clipboard. - Connect to your Raspberry Pi via SSH as described above.
- Create a new directory for your authorized keys by running
mkdir ~/.ssh
andtouch ~/.ssh/authorized_keys
. - Open the
authorized_keys
file with a text editor (e.g.,nano ~/.ssh/authorized_keys
) and paste the contents of your public key into it. Save and exit the file. - Set the correct permissions for the
.ssh
directory by runningchmod 700 ~/.ssh
andchmod 600 ~/.ssh/authorized_keys
. - Disable password authentication in the SSH config file by opening
/etc/ssh/sshd_config
with a text editor (e.g.,sudo nano /etc/ssh/sshd_config
) and settingPasswordAuthentication no
. Save and exit the file. - Restart the SSH service by running
sudo systemctl restart ssh
. - You can now connect to your Raspberry Pi using your SSH key instead of a password.
Remember, securing your Raspberry Pi is crucial when connecting remotely. Be sure to update your software regularly and keep your passwords strong. Happy hacking!