Raspberry Pi: headless setup without a monitor
Set up a Raspberry Pi without ever plugging in a monitor or keyboard. Write the SD card, SSH in, and configure Wi-Fi from your laptop.
Every Raspberry Pi project I do starts this way: I write an SD card with Raspberry Pi OS, configure Wi-Fi and SSH before the first boot, plug it in, and SSH into it from my laptop. No monitor, no keyboard, no fighting with HDMI cables.
This tutorial walks through the whole flow. If you have a Raspberry Pi you have never used, this is where to start.
What you need
- Raspberry Pi (any model: 4, 5, Zero 2 W, etc.)
- MicroSD card (32 GB or larger, A1 or A2 rated)
- MicroSD card reader (most laptops have one, otherwise a USB adapter)
- Power supply (official USB-C PSU for the Pi 4 and 5, micro-USB for the older models)
- A computer with an SD card slot or reader
- An ethernet cable or a known Wi-Fi network
Step 1: flash the SD card
Download the Raspberry Pi Imager from https://www.raspberrypi.com/software/.
Run the imager:
- Choose OS:
Raspberry Pi OS (other)>>Raspberry Pi OS Lite (64-bit). The “Lite” version has no desktop and is what you want for headless projects. Use the full version only if you plan to plug in a monitor. - Choose Storage: select your SD card.
- Click the gear icon (or
Edit settingson the macOS version):- Set hostname (e.g.
pi-pihole) - Enable SSH, set password
- Set username and password
- Configure Wi-Fi: SSID, password, country code
- Set hostname (e.g.
- Click Write.
The imager formats the card and writes the OS. This takes about 5 minutes on a fast card.
The “Lite” image is 700 MB. The full image is 3 GB. If you do not need a desktop, use Lite. The Pi is way more responsive over SSH without the desktop running.
Step 2: plug it in
- Insert the SD card into the Pi.
- Connect the Pi to your network (Wi-Fi is configured, or plug in ethernet).
- Plug in the power supply.
The Pi boots in about 20-30 seconds. The green LED on the Pi will flicker during boot.
Step 3: SSH in
From your laptop:
ssh brian@pi-pihole.local
(Replace brian with the username you set and pi-pihole with the hostname
you set.)
If you are on a different network, find the IP address of the Pi:
- Check your router’s admin page (usually
192.168.1.1or192.168.0.1). - Use a network scanner like
nmap:
nmap -sn 192.168.1.0/24
- On macOS, the hostname will appear in Finder under “Network.”
Once you find the IP:
ssh brian@192.168.1.42
Step 4: first-boot setup
The first time you SSH in, you should run:
sudo apt update
sudo apt upgrade -y
sudo raspi-config
In raspi-config, useful options:
Interface Options>>SSH(already enabled if you set it in the imager)Interface Options>>VNCif you want a remote desktopPerformance Options>>GPU Memoryto 16 MB if you are not using a desktopAdvanced Options>>Expand Filesystem(should happen automatically on modern OS images, but check)
Then exit raspi-config and reboot if it asks.
Step 5: lock down the basics
Set the timezone:
sudo timedatectl set-timezone America/Denver
(Replace with your timezone.)
Enable automatic security updates:
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
Set up a static IP (optional, but helpful for headless servers):
Edit /etc/dhcpcd.conf:
interface wlan0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=1.1.1.1 8.8.8.8
Reboot:
sudo reboot
After the reboot, the Pi is at 192.168.1.100.
The mDNS gotcha
.local hostnames (e.g. pi-pihole.local) work via mDNS (also known as
Bonjour). They work great on macOS and modern Linux. On Windows, you need
to install the “Bonjour Print Services” or enable it via the iTunes
installer. On older Windows builds, mDNS is unreliable.
If you are on Windows and .local does not work, use the IP address
instead, or set up a static DHCP reservation in your router.
Setting up SSH keys (so you do not type a password every time)
On your laptop:
ssh-keygen -t ed25519
ssh-copy-id brian@pi-pihole.local
Or, if ssh-copy-id is not available:
cat ~/.ssh/id_ed25519.pub | ssh brian@pi-pihole.local "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Then on the Pi, disable password authentication:
sudo nano /etc/ssh/sshd_config
Set PasswordAuthentication no. Save, exit, restart SSH:
sudo systemctl restart ssh
Now you can SSH in without typing a password, and password-based login is disabled (which closes a common attack vector).
When something goes wrong
- The Pi is not reachable. Check the green LED on the Pi. If it is flickering, the Pi is booting. If it is off, the SD card or power supply is bad. If it is solid, the Pi booted but the network is not configured.
- Wi-Fi password wrong. You will need to mount the SD card on your
laptop and edit
/etc/wpa_supplicant/wpa_supplicant.conf. Add the correct password and reboot. - SD card corrupted. Reflash it. This happens to about 1 in 20 cards eventually. Keep backups.
What to build next
- A Pi-hole ad blocker (the reason I have a Pi running 24/7).
- A NAS with Samba or NFS.
- A Home Assistant server.
The Pi-hole tutorial is one of the next on this site. The Home Assistant version is in the book Home Automation with Raspberry Pi.