How to pre-configure a headless Pi-OS Lite MicroSD card
Raspbian has been replaced with Pi-OS and there are 3 flavours, full fat, semi and skimmed. This post will detail a couple of extra files you should create before first boot so that you won’t need to connect a keyboard or monitor.
First steps
Create a clean Pi-OS MicroSD card, the easiest way to do this is to use the Raspberry Imager tool. Within the tool choose the Pi-OS lite option.
Once the card has been created we need to add a couple of specifically named files, one with our WiFi details and the other to enable SSH.
Wifi
Create a text file in the boot partition of the card called: wpa_supplicant.conf
Copy the text below into the file, you’ll need to replace everything in square brackets (including the bracket) with the details to match your country and network:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=[your_ISO-3166-1 two letter country code] network={ ssid="[your WiFi SSID/name]" psk="[your WiFi password]" key_mgmt=WPA-PSK }
The ISO-3166 two letter country codes are available via this link, but common ones include GB, US, FR, DE etc
SSH
To enable SSH to auto start we need to create a text file called ssh in the root of the card. The contents don’t matter just so long as it exists.
Last steps
That is essentially it, dismount/eject the card, pop it in your Pi and power it on. Wait a few minutes for the Pi to sort itself out then check your router or run nmap to find the new IP. Then you can connect to SSH using putty or similar and the default creds of pi / raspberry
Once you’ve connected you’ll probably want to update the OS:
sudo apt update && sudo apt -y upgrade && sudo apt -y autoremove
then change the defalt password
sudo passwd pi