Install Raspberry Pi OS

Written by on .

For headless with SSH over WiFi

Start by becoming root (if not yet):

su

Simple install of headless Raspberry Pi OS (Raspbian). Grab the download url of the zipped ISO here at the raspberrypi.org official website.

wget https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2021-05-28/2021-05-07-raspios-buster-armhf-lite.zip unzip 2021-05-07-raspios-buster-armhf-lite.zip

Mount the iso, in order to prepare root user and SSH over WiFi connectivity:

mkdir /tmp/rpi-os-boot /tmp/rpi-os-root losetup -Pf 2021-05-07-raspios-buster-armhf-lite.img mount /dev/loop0p1 /tmp/rpi-os-boot mount /dev/loop0p2 /tmp/rpi-os-root

Disable rfkill (a.k.a. airplane mode):

echo -n " systemd.restore_state=0 rfkill.default_state=1" >>/tmp/rpi-os-boot/cmdline.txt

Setup WiFi connection:

cat <<EOF >>/tmp/rpi-os-root/etc/wpa_supplicant/wpa_supplicant.conf country=<your-two-letter-country-code-ISO-3166-1> network={ ssid="<your-WiFi-SSID>" psk="<your-WiFi-passphrase>" } EOF

Set a root password:

sed -i -e 's/^root:[^:]*:/root:'"$(openssl passwd -6 -salt <some-arbitrary-salt> <your-new-root-passphrase>)"':/g' /tmp/rpi-os-root/etc/shadow

Enable sshd, and permit root login:

touch /tmp/rpi-os-boot/ssh sed -i -e 's/^#PermitRootLogin\s+.*$/PermitRootLogin yes/g' /tmp/rpi-os-root/etc/ssh/sshd_config

Unmount the image, and clean up:

umount /tmp/rpi-os-boot umount /tmp/rpi-os-root losetup -d /dev/loop0 rmdir /tmp/rpi-os-boot /tmp/rpi-os-root

Write the image to the Micro SD-card.

cat 2021-05-07-raspios-buster-armhf-lite.img | pv >/dev/sdX

Make sure the data has been written to the physical disk, wait for sync to complete before taking the card out:

sync

Don't forget the default user is "pi", and its password is "raspberry". You can disable it in /etc/shadow.