The three methods to enable SSH on a Raspberry Pi as commands

How to Enable SSH on Raspberry Pi: 3 Methods (Pi 4, Pi 5, Headless)

Raspberry Pi OS ships with SSH disabled by default. This is a deliberate security decision (a default-on SSH service with the well-known pi username was a known weak point on early Pi models). Enabling it is straightforward, but the right method depends on whether you have a monitor and keyboard attached, and which Pi OS version you’re on.

This guide covers the three methods Raspberry Pi’s own documentation describes, on current Raspberry Pi OS (a Debian Trixie base since October 2025).

Short answer: with a monitor and keyboard, run sudo raspi-config and choose 3 Interface Options then I1 SSH. For a headless Pi, turn on Enable SSH in Raspberry Pi Imager’s Customisation tab before you write the card, or put an empty file named ssh and a userconf.txt (your username and an encrypted password) on the bootfs partition.

Checked on: 15 November 2026. The raspi-config screens and the SSH status checks were captured on a real Raspberry Pi 4 Model B (Rev 1.4) running Raspberry Pi OS Trixie. SSH was already enabled on that Pi, so we only looked at the screens and ran read-only checks; we did not switch anything on or off. The Imager steps were run in Raspberry Pi Imager 2.0.12 on an x86 test machine in the ReadTheManual lab (every screen up to Remote access, nothing written to a card). The first-boot route (the ssh and userconf.txt files on bootfs) and the Control Centre switch follow Raspberry Pi’s getting started and configuration documentation and were not run on hardware. The login screenshot is a local demo against a throwaway test server on a side port, not the Pi’s own SSH service. The error messages in the errors section were reproduced on an Ubuntu test VM.

Opening of the Raspberry Pi news post announcing Raspberry Pi OS Trixie
Raspberry Pi OS moved to a Debian 13 “Trixie” base on 2 October 2025. Source: Trixie, the new version of Raspberry Pi OS, raspberrypi.com, 2 Oct 2025 (screenshot 28 Oct 2026).

Method 1: raspi-config (when you have a monitor + keyboard)

The official tool for changing Pi configuration.

sudo raspi-config

Navigate using arrow keys:

  1. 3 Interface Options -> Enter
  2. I1 SSH -> Enter
  3. Yes to “Would you like the SSH server to be enabled?”
  4. OK
  5. Finish to exit
raspi-config main menu on a Raspberry Pi 4 Model B with 3 Interface Options highlighted
The raspi-config main menu (started with sudo raspi-config) with 3 Interface Options highlighted. Captured on a real Raspberry Pi 4 Model B (Rev 1.4), Raspberry Pi OS Trixie (Debian 13), 15 Nov 2026.
raspi-config Interface Options menu with I1 SSH highlighted: Enable/disable remote command line access using SSH
The Interface Options menu with I1 SSH highlighted. SSH was already enabled on this Pi, so we stopped here and did not answer the Yes/No question that follows (the dialog was closed with Esc and nothing was changed). Captured on a real Raspberry Pi 4 Model B (Rev 1.4), Raspberry Pi OS Trixie (Debian 13), 15 Nov 2026.

SSH is now running and starts automatically on every boot. This is the menu path in Raspberry Pi’s raspi-config documentation. On the desktop, the same switch is under Preferences > Control Centre, on the Interfaces tab.

Verify:

sudo systemctl status ssh

You want Active: active (running).

To check the setting without opening the menu, sudo raspi-config nonint get_ssh prints 0 when SSH is enabled and 1 when it is disabled.

Terminal showing sudo raspi-config nonint get_ssh printing 0
A read-only way to check the setting: sudo raspi-config nonint get_ssh prints 0 when the SSH server is enabled and 1 when it is disabled. Nothing was changed. Captured on a real Raspberry Pi 4 Model B (Rev 1.4), Raspberry Pi OS Trixie (Debian 13), 15 Nov 2026.
Terminal showing systemctl status ssh with ssh.service loaded and enabled, Active: active (running)
systemctl status ssh –no-pager (read-only; shown here without sudo): ssh.service is enabled and Active: active (running), which is what you want to see. Captured on a real Raspberry Pi 4 Model B (Rev 1.4), Raspberry Pi OS Trixie (Debian 13), 15 Nov 2026.

Method 2: Headless setup via the boot partition (no monitor needed)

For a Pi that will run headless, when you did not use Imager’s Customisation tab. Raspberry Pi OS has had no default user since 2022, so SSH needs two files on the card, not one: an empty ssh file to turn the server on, and a userconf.txt file to create the account you will log in as. Raspberry Pi’s getting started documentation lists both under its manual setup for SSH.

After you have flashed Raspberry Pi OS to the card, and before you eject it:

  1. Open the bootfs partition. It should mount on its own and appear as a drive in your file manager. In a terminal that is cd /Volumes/bootfs on macOS or cd /run/media/$USER/bootfs on most Linux desktops.
  2. Create an empty file named ssh with no extension. On Linux or macOS: touch ssh. On Windows, create a text document in the partition, name it ssh and remove the .txt (turn on file extensions in Explorer if you cannot see it).
  3. Make the encrypted password. In a terminal on your computer run openssl passwd -6, type your password when prompted and confirm it. It prints a long string starting $6$. (The default macOS openssl is LibreSSL and does not support -6; the Raspberry Pi docs suggest installing OpenSSL with Homebrew.)
  4. Create a file named userconf.txt in the same partition containing one line: username:encrypted-password, for example alex:$6$... with the string from step 3. The docs say the username must start with a letter and use only lowercase letters, digits, underscores and hyphens, up to 31 characters.
  5. Eject the card cleanly, put it in the Pi and power on. Allow a few minutes on first boot.
cd /run/media/$USER/bootfs
touch ssh
echo "alex:$(openssl passwd -6)" > userconf.txt

The last command asks for the password twice and writes the line for you. Do not put a plain-text password in userconf.txt; it has to be the encrypted string.

On a Pi that is already running, sudo touch /boot/firmware/ssh followed by sudo reboot does the same job for SSH (remote access documentation), but the account has to exist already.

Method 3: Raspberry Pi Imager pre-config (recommended for new builds)

Raspberry Pi Imager lets you set SSH, the user and the network before the card is written. The current release is v2.0.12, and the screenshots below are from it, run on an x86 test machine in the ReadTheManual lab with nothing written to a card. They follow the Customise your operating system section of Raspberry Pi’s documentation. This is now the easiest path.

  1. Open Raspberry Pi Imager and choose your device.
  2. Choose the OS. Raspberry Pi OS (64-bit) is the recommended entry and is a port of Debian Trixie.
  3. Choose your storage device. If the OS can be customised, the Customisation steps follow. (You can use Skip customisation, but then SSH stays off.)
  4. Work through the subtabs with Next: Hostname (letters, numbers and hyphens only, for example pi5-server); Localisation (pick your capital city and Imager fills in the time zone and keyboard layout; Next stays greyed out until you do); User (a username and password, since there is no default user); Wi-Fi (a secure or open network, if going wireless); Remote access; and Raspberry Pi Connect.
  5. On Remote access, switch Enable SSH on, then choose Use password authentication or Use public key authentication. The key option adds a keys section with a Show button for your public key.
  6. Continue to Writing to write the card.
Raspberry Pi Imager 2.0.12 Choose operating system screen: Raspberry Pi OS (64-bit), a port of Debian Trixie, marked Recommended
Raspberry Pi Imager 2.0.12, choose operating system: Raspberry Pi OS (64-bit) is a port of Debian Trixie and is marked Recommended (lab screenshot, 15 Nov 2026).
Raspberry Pi Imager 2.0.12 Customisation, Choose username: username and password fields, with the other subtabs listed down the left
Customisation, User: you create the account yourself. The left-hand list shows the subtabs: Hostname, Localisation, User, Wi-Fi, Remote access and Raspberry Pi Connect. The password is masked and the account here is a throwaway one.
Raspberry Pi Imager 2.0.12 Remote access screen titled SSH authentication, with the Enable SSH switch off
Customisation, Remote access (the screen is titled “SSH authentication”): Enable SSH starts switched off, so SSH is only on if you switch it on.
Raspberry Pi Imager 2.0.12 Remote access screen with Enable SSH switched on and Use password authentication selected
With Enable SSH switched on, Use password authentication is selected by default.
Raspberry Pi Imager 2.0.12 Remote access screen with Use public key authentication selected and a section reading No SSH keys configured with a Show button
Choosing Use public key authentication shows “No SSH keys configured” and a Show button for adding your public key. Next stays greyed out until a key is added.

When the Pi boots for the first time, it already has SSH enabled, the network configured, and (optionally) your SSH key in ~/.ssh/authorized_keys. You can SSH in straight away.

This eliminates the entire “find the IP, ssh in, run raspi-config” loop. Recommended for anyone setting up multiple Pis.

Default username gotcha

Older Pi OS images shipped with a default user pi and password raspberry. This is no longer the case.

Pi OS Bullseye (April 2022) and later require you to set a username and password during first boot, in Imager’s Customisation step, or in a userconf.txt file on the card (Method 2). There is no pi user unless you explicitly create one.

Paragraphs from Raspberry Pi's April 2022 announcement that the default pi user is being removed
Raspberry Pi’s own announcement of the change: “the default “pi” user is being removed”. Source: An update to Raspberry Pi OS Bullseye, raspberrypi.com, 7 Apr 2022 (screenshot 28 Oct 2026).

If a tutorial says ssh [email protected] and the login fails with Permission denied, that’s why. Use the username you set during install (or via Imager).

To find your hostname if you forgot:

hostname    # run on the Pi to see what it's set to

By default, Pi OS uses raspberrypi.local (mDNS) but if you set a custom hostname in Imager, use that instead.

Connect to your Pi

From any other machine:

ssh [email protected]
# or
ssh [email protected]   # example address: use your Pi's own

Replace username with whatever you set during install. The .local mDNS hostname only works on networks that support mDNS (most home networks do); if it fails, find the IP from your router or by running hostname -I on the Pi via a connected monitor.

First connection prompts for the host key fingerprint: type yes, then enter your password (or use your SSH key if you set one in Imager).

Terminal showing the SSH host key question answered yes, then whoami and uname -m run on the far side of a local demo connection to 127.0.0.1 port 2222
Local demo, not the Pi’s own SSH service: this connection goes to a throwaway test SSH server on 127.0.0.1, port 2222, that the recording session started and stopped itself (key login as the capture user, so there is no password prompt). It shows the host key question you meet on a first connection and a working login. Your real login uses port 22 and a username and password or key you set up, as in the steps above. Captured on a real Raspberry Pi 4 Model B (Rev 1.4), Raspberry Pi OS Trixie (Debian 13), 15 Nov 2026.

If the connection fails: the real messages and what they mean

The messages below come from the OpenSSH client, so they look the same whatever the server is. They were reproduced on an Ubuntu test VM in the ReadTheManual lab on 15 November 2026 (a username alex, a hostname of raspberrypi.local that does not exist, and the documentation-range address 192.0.2.1), not on a Pi. The causes and fixes are the Raspberry Pi ones.

OpenSSH client errors: could not resolve hostname raspberrypi.local, connection timed out to 192.0.2.1, and connection refused on localhost port 22
Three client errors from an Ubuntu 24.04.5 test VM (OpenSSH 9.6): the .local name does not resolve, a connection to an address nothing answers on times out after 8 seconds, and a connection to a host with the SSH server stopped is refused.
  • ssh: Could not resolve hostname raspberrypi.local: ...: your computer cannot turn the .local name into an address. The lab VM printed “Temporary failure in name resolution”; the words after the colon depend on your system’s resolver. Raspberry Pi’s remote access documentation says the .local name works “if your device supports mDNS”. Fixes: check the hostname you set in Imager (it replaces raspberrypi), look up the Pi’s address in your router’s device list and use that, or run hostname -I on the Pi with a monitor attached.
  • ssh: connect to host <address> port 22: Connection timed out: the packets are going nowhere. Usual causes: the wrong address, the Pi has not joined the network (wrong Wi-Fi details or a first boot that is still running; the getting started guide says it “can take a few minutes”), or the two devices are on different networks, such as a guest Wi-Fi that isolates clients. SSH being switched off does not cause a timeout.
  • ssh: connect to host <address> port 22: Connection refused: you reached the Pi but nothing is listening on port 22. This is the message you get when SSH was never enabled, or the Pi is still starting. Enable it with one of the three methods above, or on the Pi run sudo systemctl status ssh.
  • [email protected]: Permission denied (publickey,password), usually after “Permission denied, please try again.”: the Pi is running SSH and rejecting your login. Check the username (there is no default pi user any more), retype the password, and if you chose public key authentication in Imager, use the matching private key; with key-only set up, the list in brackets is just (publickey) and a password will never be accepted.
  • WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!: you re-flashed the card and the Pi has a new host key. See “When the SD card has been used before” below to clear it.
Three wrong passwords for user alex over SSH: Permission denied, please try again, twice, then Permission denied (publickey,password)
A wrong password supplied three times (by an SSH_ASKPASS helper script, so the screenshot shows no typing) to a server that allows keys and passwords: Permission denied, please try again. twice, then Permission denied (publickey,password). Ubuntu 24.04.5 test VM.

The companion 20 Common SSH Errors guide covers more of these with a screenshot for each.

What to do next on a Pi specifically

The same hardening sequence applies as for any Linux server:

  1. Switch to SSH key auth: the SSH Key Authentication on Ubuntu guide applies identically to Pi OS.
  2. Disable password auth once keys work: see the SSH Hardening guide.
  3. Add fail2ban: particularly important for Pis exposed to the internet: see Fail2ban for SSH.
  4. Consider Tailscale or NetBird instead of port-forwarding. A mesh VPN gets you remote access without exposing port 22 to the open internet at all. Far safer for a Pi at the allotment or family member’s house.

Pi-specific quirks

SSH on Pi Zero / Pi Zero 2 W

Identical mechanics, but the WiFi-only Pi Zero models are slow on busy networks. If SSH feels laggy, check the Pi’s link speed (Raspberry Pi’s documentation uses NetworkManager’s nmcli for network details; nmcli dev wifi list, the command in its configuration documentation, marks the network you are on with * and shows its RATE and SIGNAL. The older iwconfig comes from the separate wireless-tools package, which may not be installed, so prefer nmcli).

SSH on a freshly-imaged Pi 5

Pi 5 boots faster than older Pis, but the first boot still does a lot: it applies the settings from Imager, expands the filesystem to fill the card and brings the network up. Raspberry Pi’s getting started guide warns that first boot “can take a few minutes”, so give it that long before you decide SSH has failed.

Pi OS Lite vs Pi OS with Desktop

Both have identical SSH behaviour. The Lite version skips the desktop environment but openssh-server is in both.

When the SD card has been used before

If you re-flash a card that’s been in another Pi, ~/.ssh/known_hosts on your client will have the old host key cached. You’ll get “Host key verification failed” on first connection. Clear it with:

ssh-keygen -R raspberrypi.local
ssh-keygen -R 192.0.2.100   # or whatever IP the new Pi has

Then reconnect and accept the new fingerprint.

Frequently asked questions

Why is SSH disabled by default on Pi OS?

Historical: early Pi images shipped with pi:raspberry as fixed credentials and SSH on. Anyone scanning home networks could trivially log into thousands of Pis. The Foundation locked SSH off by default to fix this. The user-set credentials and SSH-off-by-default are the remediation.

Can I enable SSH without taking the SD card out?

Yes if you can get a terminal open on the Pi (monitor + keyboard, or via the desktop GUI’s terminal app). Run sudo raspi-config and follow Method 1.

If the Pi is fully headless and you don’t have a console, you have to either pull the SD card and use Method 2, OR re-flash with Imager pre-config.

Does this work on Ubuntu running on a Pi?

The Enable SSH on Ubuntu Server guide applies if you’re running Ubuntu Server for ARM on a Pi instead of Pi OS. Mechanics there match standard Ubuntu (apt install openssh-server, ssh.socket on 24.04, etc). Pi OS uses a different default and the methods on this page.

What’s the default SSH port on Pi OS?

22, same as everywhere. Pi OS doesn’t change defaults for SSH.

My Pi is on a different subnet: how do I find it?

If .local resolution fails, options:

  1. Check your router’s DHCP client list for the Pi’s MAC address.
  2. From the Pi (with a monitor temporarily attached), run hostname -I.
  3. Use nmap from another machine: sudo nmap -sn 192.0.2.0/24 lists every device on the subnet (swap in your own network range; 192.0.2.0/24 is a documentation example).

Do I need to open a port on my router?

Only if you want to SSH into the Pi from outside your home network. For LAN-only access, no. For external access, the safer route is Tailscale or another VPN, not port-forwarding 22 to the public internet.

Where you’ll meet this at work

A headless Pi reached over SSH with a key is a small version of how admins reach Linux servers they never touch. In Azure, Azure Bastion provides SSH to Linux VMs through the portal or a native client, and Microsoft Entra ID sign-in for Linux VMs swaps copied keys for OpenSSH certificates tied to a work identity. The certificate model is plain OpenSSH, described in the ssh-keygen manual. First-boot setup maps too: Imager’s Customisation tab does the same job for a Pi that cloud-init does for an Azure Linux VM, which is to set up users, keys and packages as the machine first starts.

What does not map: Imager writes settings onto one card for one device. There is no central inventory, approval step or audit trail, and those are what the enterprise products add. What the home version does teach is the habit that carries over: never leave a login on its default, and put your own key in before the device is on a network.


Companion guides: Enable SSH on Ubuntu Server, SSH Key Authentication, SSH Hardening, Fail2ban for SSH.

Enjoyed this guide?

New articles on Linux, homelab, cloud, and automation every 2 days. No spam, unsubscribe anytime.

Scroll to Top