Raspberry Pi OS Headless Install

published:

Now, you can use the Raspberry Pi Imager and then set the ssh, password and WiFi information in the settings, before flashing the OS. This text describes how you can achieve the same thing without the official imager program.

-----

Download the Raspberry Pi OS Lite image. Use etcher or something similar to burn the image to the SD card.

In the boot partition (on the SD card), create a empty file called ssh to automatically enable the SSH server.

In newer versions of PiOS, we need to create a default user and password. Write the password into a temp file into /tmp/pi.txt as a string. The password is set on the boot partition into a file called userconf in the format username:password; the password is saved as a SHA256/SHA512 hash. To use the username pi and the password from the file /tmp/pi.txt us the following command (replace /path/to/boot/ with the path to the boot directory on the SD card):

echo -n pi: > /path/to/boot/userconf
cat /tmp/pi.txt | openssl passwd -6 -stdin >> /path/to/boot/userconf

if needed, add your wifi configuration into boot/wpa_supplicant.conf - replace YOUR-COUNTRY-CODE with your 2-letter country-code (uppercase), and your-wifi-ssid and your-wifi-password with the correct values:

country=YOUR-COUNTRY-CODE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="your-wifi-ssid"
    psk="your-wifi-password"
}

If you don't want to add your wifi password as plain text, you can use wpa_passphrase to encrpyt it:

wpa_passphrase your-wifi-ssid your-wifi-password

then use this output as your your-wifi-password value in the wpa_supplicant.conf file.

You can add muliple network blocks if you want to add different wifi configurations; the first one that works will be used.


Have a comment? Drop me an email!
This helped you? Consider buying me a ♥ coffee ♥

Latest Notes

  1. Shadowdark - Player-Driven Death Mechanics
  2. Using Syncthing to back up photos from an Android phone
  3. Real Time Beat Prediction with Aubio
  4. Performant Images on the Web
  5. mdadm with bcache and btrfs