To remote login to a Raspberry Pi, you need the SSH daemon enabled, the board's local IP address, and an SSH client on your host machine. However, running a Pi completely headless (without a monitor or keyboard) introduces a physical problem: if the network drops or the OS freezes, you have no visual feedback and no safe way to power down without corrupting the microSD card. This guide answers exactly how to remote login to Raspberry Pi 5 running Pi OS Bookworm, while wiring a hardware status node to monitor network health and trigger a safe shutdown.
Project Overview & Hardware Spec Sheet
This build assumes you are deploying a Raspberry Pi 5 (4GB variant) as a headless server or IoT node. The Pi 5 requires the official 27W USB-C PD power supply to maintain stable GPIO voltage under load, especially when driving external LEDs and monitoring network interfaces.
| Component | Exact Variant / Specification | Estimated Cost (2026) |
|---|---|---|
| Microcontroller | Raspberry Pi 5 (4GB RAM) | $60.00 |
| Power Supply | Official Raspberry Pi 27W USB-C PD (5V/5A) | $12.00 |
| Storage | SanDisk Extreme 64GB microSD (A2, V30 rated) | $14.00 |
| Indicators | 2x 5mm Diffused LEDs (Green & Red) + 2x 330Ω Resistors | $1.00 |
| Switch | 1x 6x6mm Tactile Pushbutton (Normally Open) | $0.50 |
Wiring the Headless Status & Safe-Shutdown Node
Before applying power, wire the GPIO header. We are using BCM pin numbering. The green LED indicates an active internet connection, the red LED indicates the SSH daemon is listening, and the pushbutton provides a physical safe-shutdown trigger.
| Component | BCM GPIO | Physical Pin | Wiring Notes |
|---|---|---|---|
| Green LED (Network) | 17 | 11 | Anode to GPIO 17, Cathode to 330Ω resistor, then to GND (Pin 9) |
| Red LED (SSH Active) | 27 | 13 | Anode to GPIO 27, Cathode to 330Ω resistor, then to GND (Pin 14) |
| Pushbutton | 22 | 15 | One leg to GPIO 22, opposite leg to GND (Pin 25). Uses internal pull-up. |
Headless SSH Configuration (Pi OS Bookworm)
If you are flashing a fresh microSD card and do not have a monitor to enable SSH via raspi-config, you must inject configuration files into the boot partition before inserting the card into the Pi.
- Flash the OS: Use Raspberry Pi Imager to write Pi OS Bookworm (64-bit) to your SanDisk A2 microSD card.
- Enable SSH: Open the
boot/firmwarepartition on your PC. Create an empty file named exactlyssh(no file extension). This tells the OS to enable the SSH daemon on first boot. - Set Default User: In the same
boot/firmwaredirectory, create a file nameduserconf.txt. Add a single line:pi:$6$YOUR_HASHED_PASSWORD. (You can generate the hashed password usingopenssl passwd -6on a Linux host, or use the Raspberry Pi Imager's advanced settings GUI to inject this automatically). - Configure WiFi (Optional): If using WiFi instead of Ethernet, create
NetworkManagerconnection files in/etc/NetworkManager/system-connections/post-boot, or use the Imager GUI to pre-fill SSID and PSK. Note that Bookworm deprecatedwpa_supplicant.conf. - Boot and Locate IP: Insert the card, apply the 27W PSU, and check your router's DHCP client table for a device named
raspberrypito find its assigned IP address.
Python Status Monitor & Safe Shutdown Script
This Python script targets the Raspberry Pi 5 (4GB). It uses the gpiozero library to manage the hardware pins and subprocess to poll network and SSH daemon status. It includes error handling to prevent the script from crashing if a network interface temporarily drops.
import time
import subprocess
import os
import sys
from gpiozero import LED, Button
from signal import pause
# --- Pin Definitions (BCM Numbering) ---
NET_LED = LED(17)
SSH_LED = LED(27)
SHUTDOWN_BTN = Button(22, pull_up=True, bounce_time=0.1)
def check_ssh_active():
"""Checks if the SSH daemon is actively listening on port 22."""
try:
result = subprocess.run(['ss', '-tln'], capture_output=True, text=True, timeout=2)
return ':22' in result.stdout
except subprocess.TimeoutExpired:
print('Warning: ss command timed out')
return False
except Exception as e:
print(f'Error checking SSH status: {e}')
return False
def check_network():
"""Pings a reliable external DNS to verify Layer 3 internet connectivity."""
try:
result = subprocess.run(['ping', '-c', '1', '-W', '2', '8.8.8.8'], capture_output=True, timeout=3)
return result.returncode == 0
except Exception:
return False
def safe_shutdown():
"""Triggers a safe OS shutdown to prevent SD card corruption."""
print('Shutdown button pressed. Safely powering off...')
SSH_LED.blink(0.2, 0.2)
NET_LED.blink(0.2, 0.2)
os.system('sudo shutdown -h now')
# Bind the button press event
SHUTDOWN_BTN.when_pressed = safe_shutdown
print('Status monitor active. Press Ctrl+C to exit.')
try:
while True:
NET_LED.value = check_network()
SSH_LED.value = check_ssh_active()
time.sleep(3) # Poll every 3 seconds to minimize CPU overhead
except KeyboardInterrupt:
print('Monitor stopped by user.')
sys.exit(0)
How to extend or simplify this build: To simplify, omit the LEDs and rely purely on router logs for network status. To extend, integrate the Tailscale daemon into the script's startup sequence to automatically establish a secure mesh VPN, allowing remote login over the internet without exposing port 22 to the public WAN.
Debugging: "Connection Refused" and Network Drops
When attempting to remote login, the most common failure mode on a fresh headless Bookworm install is the SSH daemon rejecting the connection. If your terminal returns this exact error string:
ssh: connect to host 192.168.1.50 port 22: Connection refused
Here are the ranked causes and the first three things to check when it fails:
- Verify the Pi actually booted (Physical Check): Look at the green ACT LED on the Pi 5 board. If it is completely dark or blinking in a repetitive, rhythmic pattern (e.g., 4 long, 4 short), the board is failing to read the microSD card or has encountered a kernel panic. The OS never reached the point of starting the SSH daemon.
- Ping the IP address (Layer 2/3 Check): Run
ping 192.168.1.50from your host PC. If the ping fails, the Pi is not on the network. Check your router's DHCP table; the Pi may have been assigned a different IP address upon booting. - Verify the
sshfile drop (Software Check): If the ping succeeds but SSH is refused, the SSH daemon is disabled. Power down the Pi, mount the SD card on your PC, and ensure the emptysshfile was placed in the root of theboot/firmwarepartition, not inside a subfolder. Windows often hides file extensions, resulting in a file actually namedssh.txt, which the Pi OS ignores.
FAQ: Remote Access to Raspberry Pi
How to remote login to Raspberry Pi without a monitor?
To remote login without a monitor (headless), you must pre-configure the OS before the first boot. Flash Pi OS using the official Raspberry Pi Imager, click the gear icon (Advanced Options) to set your username, password, and enable SSH. Alternatively, manually place an empty file named ssh and a userconf.txt file containing your hashed credentials into the boot/firmware partition of the microSD card. Once powered on and connected to Ethernet or pre-configured WiFi, use an SSH client to connect via the assigned IP.
How to remote login to Raspberry Pi over the internet securely?
Never expose port 22 directly to the public internet via router port forwarding; automated botnets will brute-force your credentials within hours. Instead, use a secure tunneling service. Tailscale or Cloudflare Tunnels are the industry standards for 2026. Install the Tailscale client on the Pi and your remote laptop; the software creates an encrypted WireGuard mesh network, allowing you to remote login using a stable 100.x.x.x IP address without touching your router's firewall rules.
How to remote login to Raspberry Pi from Windows 11?
Windows 11 includes OpenSSH natively. Open the Windows Terminal (PowerShell or Command Prompt) and type ssh username@192.168.x.x. Accept the ECDSA key fingerprint prompt on the first connection. If you prefer a GUI-based session manager with saved profiles and serial console support, download PuTTY or use the open-source alternative, MobaXterm, which also includes an integrated SFTP browser for dragging and dropping files to the Pi.






