The Direct Answer: Enabling SSHD on Raspberry Pi 5
To raspberry pi enable sshd on a headless setup, you must place an empty file named ssh (with no file extension) in the root directory of the boot partition before the first boot. Alternatively, if you are flashing your OS using the official Raspberry Pi Imager, you can enable the SSH daemon directly in the OS Customization menu under the Services tab. This triggers the OS to generate host keys and start the sshd service automatically on boot.
dhcpcd, which changes how we debug IP assignment failures. Notes for the Pi 4 Model B are included where hardware differences dictate.
Required Parts List (2026 Standard)
Do not underestimate the power requirements for the Pi 5. A brownout will silently disable the USB bus and Ethernet controller, making SSH impossible even if the daemon is running.
- Board: Raspberry Pi 5 (8GB RAM) - ~$80 USD
- Power Supply: Official Raspberry Pi 27W USB-C PD Power Supply - Crucial for enabling full 1.6A downstream USB current and preventing PCIe/network brownouts. (~$12 USD)
- Storage: Samsung EVO Plus 64GB A2 UHS-I microSD (or NVMe SSD via Pi 5 M.2 HAT+)
- Network: Cat6 Ethernet cable (preferred for headless setup) or 2.4GHz/5GHz WiFi credentials.
- Indicator Hardware: 5mm Green LED, 330Ω through-hole resistor, jumper wires.
Headless Boot: The First Three Things to Check When SSH Fails
When you attempt to connect and the terminal just hangs or rejects you, do not immediately re-flash the SD card. Run through this physical and logical checklist first.
- Verify the
sshtrigger file: If you are doing this manually, Windows and macOS often hide file extensions. You might have accidentally createdssh.txt. Plug the SD card back into your PC, enable "Show file extensions," and ensure the file is exactlysshwith no extension. - Check for Power Brownouts: On the Pi 5, if you use a standard 15W phone charger, the board will boot but throttle the CPU and disable high-power peripherals. The Ethernet PHY requires stable 3.3V/1.8V rails. If your power LED is blinking or you are using a third-party USB-C cable that lacks the proper e-marker chip for PD negotiation, the network interface will fail to initialize.
- Confirm IP Assignment via NetworkManager: Bookworm uses
nmcli. If you have a monitor attached temporarily, runnmcli device showto verify you actually received a DHCP lease. If you are strictly headless, check your router's DHCP lease table for a hostname likeraspberrypi.localor attempt to pingraspberrypi.local(mDNS must be supported by your client OS).
Exact Error Strings and Ranked Causes
Here are the exact terminal outputs you will see when the connection fails, ranked by the most likely root cause.
| Exact Error String | Ranked Causes (Most to Least Likely) | Immediate Fix |
|---|---|---|
ssh: connect to host 192.168.x.x port 22: Connection refused |
1. The ssh trigger file was missing or had a .txt extension.2. sshd crashed during host key generation.3. Local firewall (ufw) blocking port 22. |
Re-insert SD card to PC, create extension-less ssh file. If it persists, boot with a monitor and run sudo systemctl status ssh. |
ssh: connect to host 192.168.x.x port 22: Network is unreachable |
1. Your client PC is on a different subnet/VLAN. 2. Pi WiFi failed to connect (typo in wpa_supplicant.conf or Imager settings). |
Verify client IP subnet. For WiFi, ensure country code is set correctly in Imager, or switch to Ethernet. |
Connection timed out |
1. Wrong IP address (DHCP lease changed). 2. Pi 5 brownout disabled Ethernet controller. 3. Router AP isolation is enabled. |
Check router DHCP table. Swap to official 27W Pi PSU. Disable AP isolation on router. |
Permission denied (publickey,password). |
1. Default password auth disabled in Imager. 2. SSH key mismatch. 3. Typo in username (default is no longer 'pi'). |
Use the exact username created in Imager. If keys were set, ensure your local ~/.ssh/id_rsa is being passed with ssh -i. |
Pin Mapping & Hardware: Building an SSHD Status Monitor
When running a headless Pi in a server rack or an enclosed 3D-printed project box, you cannot see the terminal. We can wire a physical LED to indicate whether the sshd service is actively running and listening. This uses the standard gpiozero library native to Raspberry Pi OS.
| Component | Pi 5 Pin (Physical) | BCM GPIO | Notes |
|---|---|---|---|
| LED Anode (+) | Pin 11 | GPIO 17 | Connect via 330Ω current-limiting resistor. |
| LED Cathode (-) | Pin 9 | GND | Any ground pin works; Pin 9 is physically adjacent to Pin 11. |
Complete Python Code: Auto-Restart and GPIO Status Monitor
This script queries systemctl to check the state of the SSH daemon. If the daemon crashes or stops, the script logs the error, attempts a restart, and updates the physical GPIO LED. This code targets the Pi 5 on Bookworm OS.
#!/usr/bin/env python3
"""
SSHD Status Monitor & Auto-Recovery for Raspberry Pi 5
Target Board: Raspberry Pi 5 (Bookworm OS)
Dependencies: gpiozero (pre-installed on Raspberry Pi OS)
"""
import subprocess
import time
import logging
from gpiozero import LED
from signal import pause
# --- PIN DEFINITIONS ---
# BCM GPIO 17 corresponds to Physical Pin 11 on the 40-pin header
SSH_STATUS_LED = LED(17)
# --- LOGGING SETUP ---
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s [%(levelname)s] %(message)s',
handlers=[
logging.FileHandler("/var/log/sshd_monitor.log"),
logging.StreamHandler()
]
)
def check_sshd_status():
"""Queries systemd for the active state of the ssh service."""
try:
result = subprocess.run(
['systemctl', 'is-active', 'ssh'],
capture_output=True, text=True, check=False
)
return result.stdout.strip() == 'active'
except FileNotFoundError:
logging.error("systemctl not found. Are you running a systemd-based OS?")
return False
except Exception as e:
logging.error(f"Unexpected error querying systemctl: {e}")
return False
def restart_sshd():
"""Attempts to restart the ssh daemon via systemctl."""
logging.warning("sshd is inactive. Attempting to restart...")
try:
# Note: Running this script as root or granting passwordless sudo for systemctl is required
subprocess.run(['sudo', 'systemctl', 'restart', 'ssh'], check=True)
logging.info("sshd restarted successfully.")
return True
except subprocess.CalledProcessError as e:
logging.error(f"Failed to restart sshd. Exit code: {e.returncode}")
return False
def main_loop():
"""Main polling loop with hardware indicator."""
logging.info("Starting SSHD Monitor on GPIO 17...")
try:
while True:
is_active = check_sshd_status()
if is_active:
SSH_STATUS_LED.on()
else:
SSH_STATUS_LED.blink(on_time=0.5, off_time=0.5, background=False)
restart_sshd()
# Poll every 15 seconds to avoid CPU thrashing
time.sleep(15)
except KeyboardInterrupt:
logging.info("Monitor stopped by user.")
finally:
SSH_STATUS_LED.off()
logging.info("GPIO cleaned up.")
if __name__ == "__main__":
main_loop()
Deployment Note: To run this script automatically on boot, create a systemd service file at /etc/systemd/system/sshd-monitor.service rather than using rc.local or crontab, as systemd ensures proper dependency ordering with the network stack.
Extending and Simplifying Your Secure Shell Setup
Once you have verified that you can successfully raspberry pi enable sshd and connect, you should immediately harden and simplify the setup.
Simplifying: The Imager Method
If you are deploying multiple Pis (e.g., for a Kubernetes cluster or a sensor network), do not manually create ssh files. Use the Raspberry Pi Imager. In the OS Customization menu (Ctrl+Shift+X), you can inject your public SSH key directly. This bypasses password creation entirely and allows instant, secure, passwordless headless login on the very first boot.
Extending: Disabling Password Authentication
Leaving password authentication enabled on an internet-facing Pi is a security risk. Once your SSH keys are working:
- Open the config file:
sudo nano /etc/ssh/sshd_config - Find the line
#PasswordAuthentication yes - Change it to:
PasswordAuthentication no - Restart the service:
sudo systemctl restart ssh
This ensures that even if a botnet guesses your username, they cannot brute-force a password. For deeper security architecture, consult the official Raspberry Pi remote access documentation.
Frequently Asked Questions (FAQ)
How to raspberry pi enable sshd without monitor on first boot?
The most reliable method is to flash your microSD card using the official Raspberry Pi Imager on your desktop. Click the "Settings" gear icon (OS Customization), navigate to the "Services" tab, check "Enable SSH", and select "Use password authentication" or "Allow public-key authentication only". If you are using a third-party flasher like BalenaEtcher, mount the freshly flashed SD card on your PC, open the partition named boot or bootfs, and create a blank text file named exactly ssh (delete the .txt extension).
Why is sshd failing to start automatically on boot?
If the ssh trigger file was present but sshd still fails to start, the most common cause on Bookworm OS is corrupted host keys. This happens if the Pi loses power during the very first boot while ssh-keygen is generating the RSA/Ed25519 keys. To fix this headless, you cannot. You must plug in a monitor and keyboard, log in, delete the broken keys via sudo rm /etc/ssh/ssh_host_*, and regenerate them with sudo dpkg-reconfigure openssh-server.
How to raspberry pi enable sshd using only a Windows PC?
Windows 10 and 11 have a built-in OpenSSH client, so you do not need PuTTY anymore. Open PowerShell or Windows Terminal and type ssh username@raspberrypi.local. If Windows cannot resolve the .local mDNS address (common on older Windows builds without Bonjour installed), log into your home router's admin panel, find the Pi's assigned IPv4 address in the DHCP client list, and use ssh username@192.168.x.x instead.
Can I enable SSHD over the UART serial pins if the network fails?
Yes, but it requires a USB-to-TTL serial cable (like the CP2102 or PL2303). You must enable the serial console in /boot/firmware/config.txt by setting enable_uart=1. Connect the cable's TX to Pi GPIO 15 (RX), RX to Pi GPIO 14 (TX), and GND to GND. Never connect the 5V/VCC wire from the serial adapter to the Pi's 5V pin while the main USB-C power supply is also plugged in, or you will fry the voltage regulators. Use a terminal emulator like PuTTY at 115200 baud to access the shell and fix your network configuration.






