Having recently got a shiny new Raspberry Pi 4, and needing to figure out (again) how to set it up for a headless install with a WiFi connection and ssh access, I’m leaving these notes here for future me.
Firstly, get the latest “lite” Raspbian image:
shasum -a 256 2019-06-20-raspbian-buster-lite.zip
Check the hash against the one on the download page, then write the image to a suitable SD card (assuming macOS):
diskutil unmount /dev/disk2s1
sudo dd bs=1m if=2019-06-20-raspbian-buster-lite.img of=/dev/rdisk2 conv=sync
When it’s done mount the SD card, it should appear as a writeable
boot partition. We need to create two files here before the first boot of the new pi:
- Empty file named
sshas a shortcut to enable the openssh daemon
- Config file for
wpa_supplicantwhich will be copied (on first boot only) to the appropriate location on the main partition (
/etc/wpa_supplicant/wpa_supplicant.conf) to enable WiFi
First up create the empty file with:
Then create a config file with appropriate credentials for your WiFi network:
ssid="My WiFi network"
}' > /Volumes/boot/wpa_supplicant.conf
This is the easiest solution, but it will leave a file on disk with your WiFi password in plaintext. If you want to avoid that, you can create a hashed version on another Buster machine (or, really, any linux box with a recent version of
wpa_passphrase "My WiFi SSID" > wpa_supplicant.conf
<type secret password here: "hunter2">
If you edit the resulting file, you will see the hashed
psk= line and a commented out line above it with the plaintext version. Delete the commented out line, add the correct 2-letter country code for your region, and you’re done.
Remember: these two files must be present and correct on the first boot of the new pi, otherwise it won’t work and you’ll need to re-flash the image to the SD card and try again.