
A Raspberry Pi is most useful when it does not need a keyboard and screen. It sits on a shelf running Home Assistant, Pi-hole, a camera, or a sensor script, and you manage it from your own computer.
SSH is how you do that. SSH (Secure Shell) gives you an encrypted command line on the Pi from another machine. This guide covers turning it on, finding the Pi, connecting from macOS, Windows, or Linux, using keys instead of passwords, fixing the errors people hit most, and reaching the Pi when you are away from home.
Step 1: Enable SSH on the Pi
SSH is off by default on Raspberry Pi OS. Turn it on one of three ways.
When you flash the card (recommended). In Raspberry Pi Imager, choose your device and OS, then edit the OS customisation settings before writing:
- Set a username and password. Current Raspberry Pi OS has no default
piaccount, so this is the username you will log in with. - Optionally set the hostname, for example
garden-pi. - On the Services tab, tick Enable SSH. Choose public-key authentication if you already have a key.
This is the only method that works for a headless Pi with no screen attached.
On a Pi with a screen. Open a terminal and run:
sudo raspi-config
Go to Interface Options → SSH and choose Yes.
From the command line. On the Pi:
sudo systemctl enable --now ssh
Step 2: Find the Pi on your network
You need the Pi's hostname or IP address.
- Use its name. Raspberry Pi OS announces itself over mDNS, so
raspberrypi.local(orgarden-pi.localif you set a hostname) usually works from Macs, Linux, and recent Windows. - Ask the Pi. If you have a screen attached,
hostname -Iprints its IP address. - Check your router. The router's connected-devices or DHCP list shows the Pi by hostname and IP.
Giving the Pi a fixed address, through a DHCP reservation on your router, saves you looking it up again.
Step 3: Connect from your computer
macOS and Linux. Open Terminal:
ssh yourname@raspberrypi.local
Replace yourname with the username you set in Imager. The first time, SSH asks you to confirm the Pi's host key fingerprint. Type yes, then enter your password.
Windows 10 and 11. The OpenSSH client is built in. Open PowerShell or Windows Terminal and run the same command:
ssh yourname@raspberrypi.local
If .local names do not resolve on your Windows machine, use the IP address instead, such as ssh yourname@192.168.1.42.
Other SSH clients. PuTTY on Windows and mobile apps such as Termius work the same way: enter the hostname or IP, port 22, and your username.
When the prompt changes to something like yourname@raspberrypi:~ $, you are on the Pi.
Step 4: Use SSH keys instead of a password
Keys are more secure than passwords and save you typing. On your computer, create a key pair if you do not have one:
ssh-keygen -t ed25519
This writes a private key (~/.ssh/id_ed25519) and a public key (~/.ssh/id_ed25519.pub). The private key file starts with the line -----BEGIN OPENSSH PRIVATE KEY-----. It never leaves your computer and should never be shared.
Copy the public key to the Pi:
ssh-copy-id yourname@raspberrypi.local
On Windows, where ssh-copy-id is not included, append the contents of id_ed25519.pub to ~/.ssh/authorized_keys on the Pi.
Now ssh yourname@raspberrypi.local logs you in without a password. Once keys work, you can turn off password logins by setting PasswordAuthentication no in /etc/ssh/sshd_config on the Pi and restarting SSH with sudo systemctl restart ssh.
Can't SSH into your Pi? Common errors
Connection refused. The Pi is reachable but SSH is not running. Enable it as in Step 1.
Connection timed out or No route to host. Your computer cannot reach that address. Check the IP, check both devices are on the same network, and check the Pi is powered on and connected. Guest Wi-Fi networks often block devices from seeing each other.
Could not resolve hostname raspberrypi.local. mDNS is not working between the two machines. Use the IP address, or check the hostname you set in Imager.
Permission denied. Usually the wrong username. There is no default pi user on current Raspberry Pi OS, so use the one you created.
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED. Common after reflashing the SD card, because the Pi now has a new host key. If you know why it changed, remove the old entry and connect again:
ssh-keygen -R raspberrypi.local
How to SSH into your Raspberry Pi from outside your home
Everything above assumes your computer and the Pi are on the same local network. From a café or an office, raspberrypi.local and 192.168.x.x addresses mean nothing, and your home router blocks incoming connections.
The usual options:
- Port forwarding. Forward a port on your router to the Pi's port 22. It works, but it exposes SSH to the whole internet, where automated scanners will find it. It also fails if your provider uses CGNAT, which many mobile and fiber providers do.
- A VPN into your home network. Safer, but you now run and maintain a VPN server.
- A private network between your devices. Install a small agent on the Pi and on your computer, and they reach each other directly without anything open on your router.
noBGP is the third kind. Install the agent on the Pi:
curl -fsSL https://downloads.nobgp.com/agent/install.sh | sh
On a headless Pi, the installer prints a sign-in link and a QR code you can scan with your phone. Name the Pi when you register it, for example garden-pi, and put it in the same noBGP network as your laptop, which runs the agent too. Then, from anywhere:
ssh yourname@garden-pi
Nodes in the same noBGP network resolve each other's names, so the same command works at home, at the office, or on a phone hotspot. There is no port forward, and it works behind CGNAT. If a name does not resolve on your machine, nobgp resolve garden-pi prints the Pi's address on the noBGP network. Read the Raspberry Pi setup guide.
Or skip the SSH client
Sometimes you do not have your own computer with you. noBGP can open a browser terminal to the Pi, so any browser becomes an SSH-free shell, protected by sign-in. Read about interactive terminals.
And if you connect noBGP to Claude or ChatGPT, you can ask instead of typing: "What is the CPU temperature on garden-pi?" or "Is Pi-hole still running?" Your assistant runs the command on the Pi and reads you the answer. See how to run commands on your machines from Claude.
What SSH is and how it works
SSH stands for Secure Shell. It is a protocol for logging in to and running commands on another computer over an encrypted connection. By default an SSH server listens on TCP port 22.
When you connect, the client and server agree on encryption keys, the server proves its identity with its host key (the fingerprint you accept the first time), and then you prove yours with a password or a key. Everything after that, including what you type and what the Pi prints, travels encrypted.
Frequently asked questions
What is the default username and password for SSH on a Raspberry Pi?
Current Raspberry Pi OS has no default user. You set the username and password in Raspberry Pi Imager, or on first boot. Older images used pi and raspberry, which is exactly why that default was removed.
Can I SSH into a Raspberry Pi from my phone?
Yes. SSH apps such as Termius on iOS and Android connect the same way. Away from home, the phone needs a route to the Pi, such as being in the same noBGP network.
How do I SSH into a Pi without knowing its IP address?
Use its mDNS name, raspberrypi.local or the hostname you chose. On a noBGP network, use the node name you gave the Pi.
Is it safe to expose port 22 to the internet?
It is a common source of trouble. Internet-facing SSH is constantly probed. If you must, use keys only, disable password logins, and keep the Pi updated. A private network avoids exposing it at all.
Reach your Pi from anywhere
Install the noBGP agent on your Pi and your laptop, put them in one network, and SSH by name. Start with the agent installation guide.