fully headless setup for raspberry pi
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Kaan Barmore-Genç 2023-04-27 20:58:02 -04:00
parent ba495f25a7
commit 37114f6c45
Signed by: kaan
GPG key ID: B2E280771CD62FCF

View file

@ -0,0 +1,62 @@
---
title: "Fully Headless Setup for Raspberry Pi"
date: 2023-04-27T20:40:00-04:00
toc: false
images:
tags:
- 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:
```sh
# 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:
```sh
# replace username and password below
echo username:(echo 'password' | openssl passwd -6 -stdin) | sudo tee /mnt/userconf
```
Optional: Set up a hostname.
```sh
sync
umount /mnt
mount /dev/sdX2 /mnt
# replace host below
echo host | sudo tee /mnt/etc/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.