bgenc.net/content/posts/2023.04.27.raspberry-pi-headless-setup.md
Kaan Barmore-Genç d0527f7d0c
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Include hosts change
2023-04-27 21:05:24 -04:00

1.5 KiB

title date toc images tags
Fully Headless Setup for Raspberry Pi 2023-04-27T20:40:00-04:00 false
homelab

I always hit this issue: I have a Raspberry Pi I want to set up, but I don't want to break out the cables to hook it up to a monitor and keyboard. Luckily, the Raspbian OS actually has built-in features for this. Just follow these steps:


# Extract the Raspbian OS Lite image
xz -d <image>-lite.img.xz
# Flash the image to the SD card
dd if=<image>-lite.img of=/dev/sdX bs=4M
# Mount the boot partition
mount /dev/sdX1 /mnt
# Enable SSH
sudo touch /mnt/ssh

Create a file /mnt/wpa_supplicant.conf, with the contents:

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

network={
    ssid="wifi ssid here"
    psk="wifi password here"
}

Set up your user:

# replace username and password below
echo username:(echo 'password' | openssl passwd -6 -stdin) | sudo tee /mnt/userconf

Optional: Set up a hostname.

sync
umount /mnt
mount /dev/sdX2 /mnt
# replace host below
echo host | sudo tee /mnt/etc/hostname

Also edit /etc/hosts so 127.0.0.1 points to your new hostname.

Otherwise, just sync && umount /mnt and you are done.

If you did set up the hostname, and you have .local domains with Avahi set up, you should be able to ssh username@host.local. If you didn't, or if that doesn't work, use your router's DHCP page to find the IP address for the Raspberry Pi.