Network security

How to SSH Into Raspberry Pi: Enable, Connect and Secure It

SSH is disabled on Raspberry Pi OS by default, but turning it on takes minutes. Here are the three reliable ways to enable it, connect from any computer, and lock it down.

Cysoro Security TeamPublished · 9 min read
$ ssh [email protected]Welcome to Raspberry Pi OSalex@raspberrypi:~ $ _ NETWORK SECURITY SSH intoRaspberry Pi Enable it. Connect. Lock it down.
Quick answer

To SSH into a Raspberry Pi, enable SSH first: use Raspberry Pi Imager before flashing, run sudo raspi-config and choose Interface Options then SSH, or place an empty file named ssh plus userconf.txt on the bootfs partition for a headless setup. Then find the Pi address with hostname -I and connect with ssh username@ip-address from a terminal.

Key takeaways

  • SSH is off by default on Raspberry Pi OS, so you must enable it before you can connect.
  • Raspberry Pi Imager is the easiest route for a fresh install; raspi-config is easiest on a running Pi.
  • Switch to SSH keys, disable password logins and change the default port once SSH works.

A Raspberry Pi is most useful when you can reach it without a monitor, keyboard and mouse. SSH gives you a secure terminal over your network, so you can run commands, edit files and manage services from your main computer.

What is SSH on a Raspberry Pi?

SSH, or Secure Shell, is an encrypted protocol that gives you a remote terminal on another computer. On a Raspberry Pi it lets you type commands from your laptop and have them run on the Pi.

Everything you send, including your password, is encrypted. That is the difference between SSH and older tools such as Telnet, which sent credentials in plain text. SSH also powers file transfer through SCP and SFTP, so the same connection moves files as well as commands.

Most Pi projects end up headless: the Pi sits by a router, in a cupboard, or inside a robot, with no screen attached. SSH is how you manage it in that state. Our guide to securing your Wi-Fi is worth reading first, because SSH runs over that same home network.

What do you need before you start?

You need a Raspberry Pi running Raspberry Pi OS, a computer on the same network, and a user account on the Pi. You also need the Pi connected by Ethernet or Wi-Fi.

  • A Raspberry Pi — any model from the Pi Zero 2 W up, with Raspberry Pi OS installed.
  • A computer — Windows 10 or 11, macOS or Linux, all of which include an SSH client.
  • A network connection — Ethernet is simplest for a first connection; Wi-Fi works once it is configured.
  • A user account — created in Imager, in the first-boot wizard, or with userconf.txt.

Since April 2022 there is no default pi user. If a guide tells you to log in as pi with the password raspberry, it is out of date. Use the username you created instead.

How do you enable SSH with Raspberry Pi Imager?

Raspberry Pi Imager is the easiest route for a fresh install, because it sets the user, Wi-Fi and SSH in one pass before the card is written. The Pi then boots with SSH already running.

  1. Download and open Raspberry Pi Imager on your computer and insert the microSD card.
  2. Choose your Pi model, choose Raspberry Pi OS, and choose the microSD card as storage.
  3. Click Next and open the Customisation step, then set a hostname, username and password.
  4. On the Services or Remote Access tab, turn on Enable SSH and choose password or public-key authentication.
  5. Add your Wi-Fi network and password if the Pi will connect wirelessly, then write the card.

Insert the card, power on the Pi, and wait a minute for it to boot and join the network. You can then connect straight away, with no monitor needed at any point.

Three ways to enable SSH1. ImagerBefore flashingSets user, Wi-Fiand SSH togetherBest for fresh installs2. raspi-configOn a running PiInterface Optionsthen SSH, then YesBest with a monitor3. ssh fileOn the bootfspartition, plususerconf.txtBest headless, no ImagerAll three end the same way: SSH running, ready for your first login.
Pick the method that matches your starting point. Illustration by Cysoro.

How do you enable SSH with raspi-config?

If the Pi is already running and you have a monitor and keyboard, raspi-config is the fastest option. It is the official configuration tool built into Raspberry Pi OS.

  1. Open a terminal on the Pi and run sudo raspi-config.
  2. Choose 3 Interface Options, then I1 SSH.
  3. Choose Yes when asked whether the SSH server should be enabled, then OK and Finish.
  4. Check it with sudo systemctl status ssh — you want to see Active: active (running).

You can also enable SSH from the desktop: open Preferences, then Raspberry Pi Configuration, go to the Interfaces tab, set SSH to Enabled, and click OK. No reboot is needed either way.

Linuxize covers all three enable methods with the same raspi-config path, which is a useful cross-check if a menu label has moved in a newer release.

How do you enable SSH on a headless Raspberry Pi?

A headless Pi has no monitor, so you enable SSH by editing files on the microSD card from another computer. Since 2022 this needs two files, not one: an empty ssh file and a userconf.txt file.

  1. Flash Raspberry Pi OS to the card, then reinsert the card in your computer so the bootfs partition mounts.
  2. Create an empty file named exactly ssh with no extension in bootfs. On macOS or Linux, run touch ssh in that folder.
  3. Create the user account: run openssl passwd -6, type your password, and copy the long string it prints.
  4. Create userconf.txt in bootfs with one line: username:encrypted-password, using the string from step 3.
  5. Eject the card, put it in the Pi, and power it on. The Pi enables SSH on first boot and deletes the ssh file.

On Windows, create a text file in File Explorer, rename it to ssh, and remove the .txt extension — turn on file extensions first so you can see it. If you only add the ssh file and no user exists, SSH will refuse logins until an account is set up.

How do you find your Raspberry Pi IP address?

You need the Pi IP address, or its hostname, to connect. The simplest way is to ask the Pi itself: run hostname -I in a terminal and note the first address shown.

Without a monitor, check your router admin page under connected devices, or use a network scanner app on your phone. The Pi usually appears with a hostname such as raspberrypi, and you can often connect with raspberrypi.local instead of an address.

If your router gives the Pi a new address after every reboot, set a DHCP reservation for it in the router settings. That keeps the address stable and saves you hunting for it each time. You can check your own public address with the free what-is-my-IP tool, though that is not the address you use on your home network.

How do you SSH into a Raspberry Pi?

Open a terminal on your computer and run ssh username@ip-address, replacing the username and address with your own. On first connection you will see a host-key warning — check the fingerprint, then type yes.

For example, if your username is alex and the Pi is at 192.168.1.42, the command is ssh [email protected]. Enter your password when prompted and you will land at the Pi command prompt.

On Windows 10 and 11, PowerShell and Command Prompt both include the SSH client, so no extra software is needed. On older Windows, PuTTY is the usual choice: enter the IP address, choose SSH, and click Open. Raspberry Pi Magazine walks through the same first connection from Windows, Mac and Linux.

Your computerHow to connectNotes
macOSTerminal: ssh username@ip-addressSSH client is built in
LinuxTerminal: ssh username@ip-addressSSH client is built in
Windows 10 / 11PowerShell: ssh username@ip-addressOpenSSH client is built in
Older WindowsPuTTY: enter IP, choose SSH, click OpenDownload PuTTY first
Hostname instead of IPssh [email protected]Works when mDNS is available

How do you set up SSH keys for passwordless login?

SSH keys replace passwords with a key pair: a private key that stays on your computer and a public key stored on the Pi. They are both more convenient and much harder to guess than a password.

  1. On your computer, run ssh-keygen -t ed25519 and accept the defaults. Add a passphrase to protect the private key.
  2. Copy the public key to the Pi with ssh-copy-id username@ip-address and enter your password once.
  3. Test it by running ssh username@ip-address again — it should log you in without a password prompt.
  4. Once keys work, disable password login (see the hardening section below) so passwords cannot be guessed at all.

In Raspberry Pi Imager you can paste a public key during setup instead, under the Remote Access tab, by choosing public-key authentication. That gives you key login from the very first boot.

How do you transfer files over SSH?

SSH includes file transfer, so you do not need a separate server. The scp command copies a file in one line, and SFTP gives you a file-browser view of the Pi.

To copy a file to the Pi, run scp myfile.txt username@ip-address:/home/username/ from your computer. To copy a file back, reverse the order: scp username@ip-address:/home/username/myfile.txt .

For frequent transfers, use an SFTP client such as FileZilla: connect with the Pi hostname or IP, port 22, your username, and your password or key file. You can then drag files between your computer and the Pi.

Your SSH connection, end to endYour laptopssh [email protected]private key stays hereRaspberry PiSSH server, port 22public key checks youencrypted tunnelCommands, files and passwords travel inside the tunnel — never in plain text.
SSH encrypts the whole session between your computer and the Pi. Illustration by Cysoro.

Why can't I SSH into my Raspberry Pi?

Most SSH failures come from a short list of causes. Work through them in order instead of reinstalling the operating system.

  • Connection refused: SSH is not enabled or not running. Enable it and check sudo systemctl status ssh.
  • Connection timed out: the Pi is off, on a different network, or the IP address is wrong. Ping the address first.
  • Permission denied: the username or password is wrong, or no user account exists yet. Create one with userconf.txt or Imager.
  • Host key warning changed: the Pi was reinstalled and its key changed. Only accept this if you expect it, then remove the old key with ssh-keygen -R ip-address.
  • Wrong network: your computer is on a guest Wi-Fi network that blocks device-to-device traffic. Join the main network.

Read the Manual documents the current headless pitfalls, including the userconf.txt step that older guides omit. If SSH worked before and stopped after an update, check that the service is still enabled with sudo raspi-config nonint get_ssh, which prints 0 when SSH is on.

How do you secure SSH on a Raspberry Pi?

An SSH server on a home network is a target the moment it is reachable, so harden it as soon as it works. The biggest win is removing password login entirely.

  1. Use SSH keys and disable passwords. In /etc/ssh/sshd_config, set PasswordAuthentication no, then restart with sudo systemctl restart ssh.
  2. Change the port. Move SSH off port 22 to a high port such as 2222 with Port 2222 in the same file. This cuts automated scans, though it is not a substitute for keys.
  3. Use a strong, unique password for the Pi user while passwords are still enabled. Generate one with the free password generator and store it in a password manager.
  4. Install fail2ban. It blocks IP addresses after repeated failed logins: sudo apt install fail2ban.
  5. Keep the Pi updated. Run sudo apt update && sudo apt full-upgrade regularly so the SSH server stays patched.
  6. Do not forward port 22 from your router unless you have keys, fail2ban and a real need. A VPN is safer for remote access.
Never expose a Pi with a weak passwordAutomated bots scan the internet for open SSH ports and try common passwords thousands of times a day. A Pi with password login and a guessable password can be compromised within hours of being exposed.

Can you SSH into a Raspberry Pi from outside your home?

Yes, but do it through a VPN or a managed service rather than opening a port on your router. Port forwarding puts your Pi directly on the internet, where bots will find it.

Raspberry Pi Connect is the official free option: it gives you remote shell access through the Raspberry Pi website without opening ports. A home VPN, such as WireGuard on your router or another Pi, is the other safe route — you connect to the VPN first, then SSH as if you were at home.

If you must forward a port, use a non-standard port, SSH keys only, and fail2ban. Check the forwarded port from outside your network and confirm that password login really is off before you rely on it.

The bottom line

Enabling SSH on a Raspberry Pi takes minutes once you know which method fits your setup: Imager for a fresh card, raspi-config for a running Pi, or the ssh and userconf.txt files for a headless one. After that, one command connects you.

Do not stop at a working connection. Switch to SSH keys, disable password login, and keep the Pi updated — then it stays a convenient tool instead of an open door. If you run other devices on the same network, work through our small business cybersecurity checklist to lock those down too.

Frequently asked questions

Why is SSH disabled on Raspberry Pi by default?

SSH has been disabled by default since November 2016 to stop attackers logging in to internet-exposed Pis with known default credentials. You must turn it on deliberately, and since 2022 you must also create your own user account, because the old pi user no longer exists.

What is the default username and password for Raspberry Pi SSH?

There is no default username or password on current Raspberry Pi OS images. You create a username and password in Raspberry Pi Imager, in the first-boot setup wizard, or with a userconf.txt file. Older images used pi and raspberry, and you should change those credentials at once if you still have them.

How do I find my Raspberry Pi IP address?

On the Pi, run hostname -I in a terminal, or hover over the network icon on the desktop. On your router, look in the connected-devices list. You can also use raspberrypi.local as the hostname on many home networks if mDNS is working.

Can I SSH into a Raspberry Pi without a monitor?

Yes. That is a headless setup. Use Raspberry Pi Imager to set the user, Wi-Fi and SSH before you flash the card, or add an empty file named ssh and a userconf.txt file to the bootfs partition of an already-flashed card, then boot the Pi and connect over the network.

Why do I get connection refused when I SSH into my Raspberry Pi?

Connection refused usually means the SSH server is not running or not enabled on the Pi. Enable it with raspi-config or Imager, check it with sudo systemctl status ssh, and confirm the Pi and your computer are on the same network and you are using the right IP address.

Is it safe to expose Raspberry Pi SSH to the internet?

No, not with password login on the default port. Bots scan port 22 constantly. If you need remote access from outside your home, use a VPN, Raspberry Pi Connect, or SSH keys with password login disabled and fail2ban installed. Never forward port 22 with a weak password.

How do I SSH into a Raspberry Pi from Windows?

Windows 10 and 11 include the OpenSSH client, so open PowerShell or Command Prompt and run ssh username@ip-address. On older Windows, install PuTTY, enter the Pi IP address in the host field, choose SSH as the connection type, and click Open.

How do I copy files to a Raspberry Pi over SSH?

Use scp from your computer, for example scp file.txt username@ip-address:/home/username/, or use SFTP in a client such as FileZilla with the same host, username and password or key. The Pi runs an SFTP server automatically once SSH is enabled.

Sources

  1. Linuxize — How to Enable SSH on Raspberry Pi
  2. Read the Manual — How to Enable SSH on Raspberry Pi: 3 Methods
  3. Raspberry Pi Magazine — SSH: Remote control your Raspberry Pi
  4. Raspberry Tips — Enable SSH on Raspberry Pi: Imager, Headless and Fixes
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against Raspberry Pi remote-access documentation and current Raspberry Pi OS setup guides.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free