SSH Config for Raspberry Pi
Set up SSH config for Raspberry Pi access on local network and remotely. Covers mDNS hostname, key-based auth, and port forwarding for IoT development.
Detailed Explanation
SSH Config for Raspberry Pi
Raspberry Pis are commonly accessed via SSH for headless management, IoT development, and home server administration. A proper SSH config simplifies repeated connections.
Local Network Config
Host pi
HostName raspberrypi.local
User pi
IdentityFile ~/.ssh/id_ed25519_pi
IdentitiesOnly yes
ServerAliveInterval 30
ServerAliveCountMax 3
Using mDNS (Avahi)
Raspberry Pi OS includes Avahi, which broadcasts the hostname via mDNS. You can reach it as raspberrypi.local (default) without knowing the IP address. If you changed the hostname:
Host my-pi
HostName mypi.local
Multiple Pis
If you manage several Raspberry Pis:
Host pi-web
HostName 192.168.1.101
User pi
Host pi-sensor
HostName 192.168.1.102
User pi
Host pi-*
IdentityFile ~/.ssh/id_ed25519_pi
IdentitiesOnly yes
ServerAliveInterval 30
The Host pi-* wildcard block applies shared settings to all Pi entries.
Initial Setup
Before SSH config works, you need to enable SSH on the Pi:
- Desktop: Preferences > Raspberry Pi Configuration > Interfaces > SSH
- Headless: Place an empty file named
sshon the boot partition - Raspberry Pi Imager: Enable SSH in the Advanced Options
Copying Your Key
ssh-copy-id -i ~/.ssh/id_ed25519_pi pi@raspberrypi.local
Port Forwarding for Remote Access
To access your Pi from outside your network, forward a port on your router and create a config entry:
Host pi-remote
HostName your-public-ip.example.com
User pi
Port 2222
IdentityFile ~/.ssh/id_ed25519_pi
Use Case
Hobbyists and IoT developers who manage one or more Raspberry Pis via SSH for home automation, media servers, sensor networks, or development projects.