Securely Access Your Raspberry Pi Remotely with SSH

Learn how to securely connect to your Raspberry Pi using the Secure Shell (SSH) protocol. …


Updated August 22, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to securely connect to your Raspberry Pi using the Secure Shell (SSH) protocol. SSH, or Secure Shell, is a cryptographic network protocol used for secure remote access and communication between two devices. In this article, we’ll discuss how to SSH into a Raspberry Pi from another device, such as a computer or smartphone. This allows you to run commands on your Raspberry Pi remotely without needing to connect it to a monitor, keyboard, and mouse.

Prerequisites:

  • A Raspberry Pi with Raspbian or another compatible operating system installed.
  • Another device (e.g., computer, smartphone) that can access the internet and has an SSH client installed.
  • The IP address of your Raspberry Pi. If you don’t know it, you can find it by running hostname -I on your Pi or checking your router’s configuration page.

Step 1: Enable SSH on Your Raspberry Pi

By default, SSH is disabled on a fresh installation of Raspbian. To enable it, follow these steps:

  1. Open the terminal on your Pi and run sudo raspi-config.
  2. Navigate to “Interfacing Options” and select “SSH”.
  3. Choose “Yes” when asked if you want to enable SSH.
  4. Select “Finish” to save and exit the configuration tool.
  5. Reboot your Pi by running sudo reboot.

Step 2: Set Up a Username and Password (Optional)

If you haven’t already, set up a username and password for your Raspberry Pi. This is not strictly necessary if you plan to use SSH keys instead of passwords, but it can make the process easier for beginners. To do this, run sudo raspi-config again:

  1. Navigate to “System Options” and select “Change User Password”.
  2. Follow the prompts to set a new password for your Pi user account.

Step 3: Connect Using an SSH Client

Now that you have SSH enabled on your Raspberry Pi, you can connect from another device using an SSH client. Here are some common clients and their connection instructions:

Windows (Putty)

  1. Download and install PuTTY if you haven’t already.
  2. Open PuTTY, enter your Raspberry Pi’s IP address in the “Host Name” field, and click “Open”.
  3. Enter your username and password (or SSH key passphrase) when prompted.

macOS/Linux (Terminal)

  1. Open a terminal window on your computer or smartphone.
  2. Run ssh pi@<IP address> where <IP address> is the IP of your Raspberry Pi. For example, ssh pi@192.168.1.100.
  3. Enter your username and password (or SSH key passphrase) when prompted.

Android (ConnectBot)

  1. Install ConnectBot from the Google Play Store.
  2. Open ConnectBot and create a new connection with your Raspberry Pi’s IP address, username, and password (or SSH key passphrase).
  3. Click “Connect” to establish an SSH session.

Once connected, you can run commands on your Raspberry Pi just like you would locally using the terminal. When you’re finished, simply type exit to close the connection.

Additional Tips:

  • If you want to connect without entering a password each time, consider setting up SSH keys for authentication. This is more secure than using passwords and can be a bit quicker. This tutorial explains how to do it with Raspbian.
  • If you’re connecting from outside your local network, you may need to forward port 22 on your router to your Pi’s IP address. Consult your router’s documentation for instructions on how to do this.
  • Be careful when running commands remotely! If you make a mistake, it can affect your Raspberry Pi’s operation. Always double check what you’re doing and use caution when deleting or modifying files.