bgenc.net/content/posts/2023.04.27.raspberry-pi-headless-setup.md

65 lines
1.5 KiB
Markdown
Raw Normal View History

2023-04-27 19:58:02 -05:00
---
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
```
2023-04-27 20:05:24 -05:00
Also edit `/etc/hosts` so `127.0.0.1` points to your new hostname.
2023-04-27 19:58:02 -05:00
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.