Raspberry Pi: Use SSH to Remote Control Your Raspberry Pi: A Complete Guide

More Tips & Tricks

how to use ssh on raspberry pi

Use SSH to Remote Control Your Raspberry Pi: A Complete Guide

Being able to control your Raspberry Pi from another computer is an important part of the Pi learning curve. There are many options for remote access, so why is SSH the protocol beginners should start with? If you’re new to Linux, Raspberry Pi, or just SSH, you’ve come to the perfect place: I created this guide to answer all of your questions about this method.

SSH is a protocol available on Linux systems that will execute commands from another computer. It needs to be enabled in the Raspberry Pi configuration first, and then an SSH client from another computer will be able to connect to the Raspberry Pi.

I will guide you through the whole process, showing you how to activate SSH, find your IP address, and connect to the Raspberry Pi from your computer.

Table of Contents

What is SSH in Raspberry Pi?

Let’s start at the beginning. If you have no idea what SSH is, I probably need to introduce a few things before giving you the procedure to use it.

SSH stands for Secure SHell. It’s a common network protocol that’s used to connect from one computer to another safely. The communication between the two computers is encrypted, and authentication is required.

It’s generally used by system administrators to access and manage remote servers. As a sysadmin, I had around 20 servers to monitor, and by using SSH, I could work on them for days without having to walk over to the server room. It’s very convenient in this case.

But even at home, it can be really useful to access your Raspberry Pi, run a few commands, and disconnect. For example, if your Raspberry Pi is mounted inside a robot, hidden somewhere, or if you’re just too lazy to plug in a monitor, SSH is a time saver.

SSH is convenient because it’s simple. You just need to have your Raspberry Pi powered on, connected to the network, and SSH enabled. I will explain how to use it next.

Step 1: Enable SSH on Raspberry Pi

On Raspberry Pi OS, SSH is disabled by default. So, your first step is to enable it. There are different methods to achieve this, depending on your current setup.

Here are the main ways to enable SSH on Raspberry Pi:

  • On Raspberry Pi OS Desktop: Enable SSH in the Raspberry Pi Configuration tool under the “Interfaces” tab.
  • On Raspberry Pi OS Lite: Use raspi-config and go to the “Interfaces” submenu.
  • With Raspberry Pi Imager: Apply advanced options when flashing the SD card.

I will now explain all these methods (and more) in detail.

SSH on Raspberry Pi OS Desktop

If you use Raspberry Pi OS Desktop, SSH isn’t enabled by default. You can enable it easily via the Raspberry Pi Configuration tool:

  • Open the desktop main menu > Preferences > Raspberry Pi Configuration
  • Switch to the “Interfaces” tab.
  • You’ll get something like:
  • Click the slider to enable SSH.
  • Close the window. The SSH server is now enabled and ready to be connected to.

By the way, if you have a desktop environment installed, you can use graphical remote access instead of SSH. VNC is one popular method, but there are many other options. It will give you access to the full GUI, not just the command line.

SSH on Raspberry Pi OS Lite

If you’re running the Lite version of Raspberry Pi OS, there’s no desktop environment, so you can’t use the Configuration tool. However, there’s a similar tool on the command line:

  • Launch raspi-config by typing the command:
    sudo raspi-config
  • You’ll get a menu wizard that configures many things on your Pi. You can use it to easily enable SSH.
  • Go to “Interface Options”:

    You can use the arrows on your keyboards to move from one item to another, and the TAB key to access the action below.
  • Then, select “SSH” and choose “Yes” to enable it.
  • Close raspi-config. SSH is now enabled.

SSH During SD Card Creation

Enabling SSH With Raspberry Pi Imager

If you’re installing Raspberry Pi OS with Raspberry Pi Imager, you can use its advanced options to enable SSH. Here’s how:

  • Run Raspberry Pi Imager (if you don’t have it, you can download it from there).
  • Choose your Pi model, any version of Raspberry Pi OS from the Operating System list, and your storage device (probably your SD card.)
  • Hit Next and a popup will appear asking for “OS customisation settings.” Click Edit Settings.
    This option may also work with other distributions like Ubuntu. If it’s not supported, the button won’t show up.
  • Under the “General” tab, set your username and password:
    raspberry pi imager customization settings username and password
  • Switch to the “Services” tab, check the “Enable SSH” box, and hit Save:
    raspberry pi imager services enable ssh
  • Now you should be back at the popup. Click YES.
    raspberry pi imager customization settings popupYour SD card will proceed to be flashed as usual.
    SSH will be enabled on the first boot.

You can find my complete guide about Raspberry Pi Imager here, to learn all the tips and tricks for this very useful tool.

Enabling SSH Manually

If you’re not using Raspberry Pi Imager to flash your SD card, or want to enable SSH on an SD card you’ve already flashed previously, you can also enable SSH manually:

  • Insert your SD card into your computer’s SD card reader.
  • Browse to it with your file explorer (generally named “boot”).
    viewing boot partition on sd card using windows
  • Create a new file in the SD card’s boot partition, named “ssh” without extension.
    If you’re on Windows, make sure it doesn’t create “ssh.txt” or something like that. You might need to enable displaying extensions in your file explorer settings.
  • Safely eject the SD card. SSH will be enabled on the next boot.

SSH on Other Linux Distributions

If you’re using Linux distributions other than Raspberry Pi OS, most of these solutions won’t work, so you’ll need to do things differently. In most cases, SSH is either enabled by default.

But if not, you can generally get an SSH server running easily with a few commands:

  • Install SSH on a Debian-based distribution:
    sudo apt install openssh-server
  • Start the SSH service:
    sudo systemctl start ssh
    sudo systemctl enable ssh

If your distribution is not based on Debian, use the corresponding package manager to do the same thing. You’ll surely find this in the distribution documentation, as it’s one of the most common steps after a system installation.

Step 2: Prerequisites to SSH into a Raspberry Pi

Now that an SSH server is enabled on your Raspberry Pi, we only need to do a few more things before connecting to it.

Find the Raspberry Pi IP address

An IP address is the identifier of your device on the network. You need it to establish the SSH connection, as your computer needs to know where to access the Raspberry Pi.

If you have a desktop environment, you can find your Pi’s IP by hovering over the network icon (top-right corner on Raspberry Pi OS), or in the system settings.

ip address using raspberry pi os

On Raspberry Pi OS Lite (or other minimal distributions), use the following command instead:
ip a

ip address using command line

The IP address format is something like A.B.C.D with each number having a value between 1 and 254. In my example, the IP address of my Raspberry Pi is 192.168.1.69—take note of your IP, as you’ll need it later.

Want an easier way with your phone?
If you’re on Android, install the RaspberryTips App, and it will quickly find your Raspberry Pi’s IP address for you! You can even use the app to connect via SSH.

SSH Login and Password

When you connect to SSH, you’ll need authenticate. By default, you can connect with your existing Raspberry Pi OS username and password, so it shouldn’t be complicated.

If you have amnesia and don’t remember your username, use the ‘whoami’ command:
whoami command on linux to find username

If you don’t remember your password, open the main menu > Preferences > Raspberry Pi Configuration tool and set a new password.

Step 3: Connect to Raspberry Pi via SSH

We now have everything we need to connect to the Raspberry Pi via SSH for the first time. There are several methods you can use. You can either use the command line for a quick test or install an SSH client for more convenience.

Connecting to SSH on the Command Line

SSH is well integrated with most modern operating systems, so it’s generally possible to use it directly from your computer’s command line. The syntax is the same, whatever your operating system is (Windows, macOS, Linux):
ssh <username>@<ip_address>

So, in my example:
ssh pat@192.168.1.69

On Windows, find the command prompt in the main menu and type the command. Upon connecting, the Pi will ask for you to enter your password:

ssh connection using windows cmd

Getting a new prompt (pat@rptips:~$) means you’ve successfully connected to your Pi!

If your computer is running Linux, you may need to install an SSH client manually with your package manager (“sudo apt install ssh” or something like that). But in most distributions, it’s already installed by default.

Connecting With an SSH Client

Using the terminal or command prompt on your computer is the fastest way to test if SSH is working, but it’s not the most convenient or comfortable to use. There are many SSH clients that will give you a better experience (more features, better interface, etc.).

The most commonly-known one for Windows users is PuTTY, which you can download from here. It works great, and you can save your sessions, to allow you to simply connect to each device in one click, without having to remember the IP address.

But my favorite client is Termius. You’ll find it in the Microsoft Store or directly on their website. It looks great, saves your sessions and passwords, and allows you to reconnect in one click when the connection is lost.

termius ssh client interface

On Linux and macOS, I generally create aliases for my servers and don’t use any specific client. But you can probably find some similar options (Termius is available on macOS and Linux, for example).

Going Further With SSH on Raspberry Pi

That’s it! You’ve completed the most complicated part and can now access your Raspberry Pi terminal from your computer. But in fact, it’s only the beginning. It gives you access to new work, and probably new projects if you’re doing it right.

Raspberry Pi Commands

Getting access to the Raspberry Pi terminal from your computer is fine, but you’ll need to know some commands, or it’ll be useless. Using a terminal is like speaking a different language, you’ll need to spend time learning and testing the Linux commands.

Remembering the commands can be pretty difficult, but I’ve got you covered. You can read this article where I give you the most important commands, with a short explanation of the syntax and a few examples. You can even download my cheat sheet with all of them in a convenient PDF format.

Connect to SSH Without a Password

If you only have one Raspberry Pi with a simple password that you remember easily, it’s fine. But when you have several servers running and need to access them regularly, it might be a mess.

It’s possible to use public-key authentication to access your Raspberry Pi without a password. In short, you’ll register your computer on the Raspberry Pi, to allow it remote access without any password in the future.

Raspberry Pi Security Tips

If SSH is disabled by default on most distributions, including Raspberry Pi, there’s a reason for it. As soon as you enable it, there’s a risk that someone can access your Pi without your permission.

For example, if you use the same username and password everywhere, and someone gets access to another PC on your network, they can easily get access to your Raspberry Pi, too. But even if you have different passwords, there are still risks involved with having SSH enabled.

Use a VPN for Remote Access Over the Internet

The IP address you have on your Raspberry Pi is a private IP address, something local, that doesn’t exist on your company network. If you want to access your Raspberry Pi from elsewhere, the best method is to use a VPN.

A VPN will create a secure tunnel between your computer (anywhere in the world) and your Raspberry Pi at home. A VPN server needs to be installed on your Raspberry Pi (or another device on your home network) as well as a VPN client on your computer (or smartphone).

More Tips & Tricks

DistroSea.com site image
Check out different Linux distros in your web browser with nothing to download at DistroSea.com
Quick Ref Site image
Here are some cheatsheets and quick references from QuickRef.ME.
edX Site image
Learn Linux from MIT for FREE edX.
Linux Basics YouTube Series Site image
Linux Basics YouTube Series
Watch the Series.
“Linux Command Line Tutorial For Beginners" will teach you everything you need to know about Linux Command Line in easy-to-understand language.
Watch the Series.