snippets > connect-headless-raspberry-pi-through-ssh-first-time

August 29, 2020 (updated at: May 15, 2022)

Connect to a headless Raspberry Pi through SSH for the first time

This will work for Raspberry Pi OS (formerly known as Raspbian); no monitor or keyboard is needed.

After flashing the OS, create a wpa_supplicant.conf file on the boot partition of your SD card (not the boot folder).

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert 2-letter ISO 3166-1 country code here>

network={
 ssid="<Name of your wireless LAN>"
 psk="<Password for your wireless LAN>"
}

On the same partition, create an empty file called ssh. It will instruct the OS to enable the SSH server. Also, create your SSH user by creating a file named userconf.txt.

touch ssh

echo <user>:`echo '<pass>' | openssl passwd -6 -stdin` > userconf.txt

To find the Raspberry Pi on your local network, you can use nmap. Assuming your local IP addresses start with 192.168.0, run:

nmap -sn 192.168.0.0/24

If your Pi has connected correctly, you will see something similar to the following in the output.

Nmap scan report for raspberrypi (<IP>)
Host is up (0.11s latency).
MAC Address: <MAC> (Raspberry Pi Trading)

Further reading

Official docs on remote access and Wi-Fi settings.

Security concerns about default user and password for SSH