← Back to Articles

Configure a Headless Raspberry Pi Before First Boot

Configure a headless Raspberry Pi before first boot using Raspberry Pi Imager or manual SD card edits. No monitor, no keyboard required.

The Pi is already mounted inside the enclosure. The enclosure is already bolted to the wall. There is no HDMI port accessible, no USB keyboard handy, and the device needs to be on the network in twenty minutes. This is the moment most people realize they should have configured the Pi before it left the bench.

Headless configuration, done before first boot, means the Pi connects to the network and accepts SSH logins the moment power is applied. No monitor. No keyboard. No guesswork. This guide covers exactly how to do it, for both Raspberry Pi OS Bookworm (the current release) and older Bullseye images, since the method changed significantly between the two.

Two Configuration Paths

There are two ways to write headless configuration to an SD card before first boot. The first is through Raspberry Pi Imager, which handles everything inside a GUI during the write process. The second is by editing files directly on the boot partition after writing the image. Both work. Imager is faster for a single device. Direct file editing is easier to script for a fleet.

Using Raspberry Pi Imager

Download and install [Raspberry Pi Imager](https://www.raspberrypi.com/software/) from the official site. Insert the SD card into a card reader connected to your workstation.

  1. Open Imager and choose your OS. Raspberry Pi OS Lite (64-bit) is the correct choice for headless deployments. It has no desktop environment.
  2. Choose your storage device. Double-check the target. Imager will overwrite whatever is selected.
  3. Click the gear icon (or press Ctrl+Shift+X on Windows/Linux, Cmd+Shift+X on macOS) to open the Advanced Options panel before writing.
  4. Set hostname, enable SSH, choose 'Use password authentication' or paste a public key, and configure your Wi-Fi credentials if needed.
  5. Click Save, then Write. Imager embeds the configuration directly into the image.

In Raspberry Pi OS Bookworm (released late 2023), SSH is disabled by default and the 'ssh' touch file is no longer supported. The only supported methods are Imager's Advanced Options or the firstrun.sh approach described below. Do not rely on the old empty 'ssh' file if you are writing a Bookworm image.

Manual Configuration on the Boot Partition

After writing the image with Imager (without using Advanced Options) or any other tool, the boot partition is visible as a small FAT32 volume on any OS. On macOS and Windows it appears automatically. On Linux it mounts at a path like /media/username/bootfs.

Raspberry Pi OS Bookworm uses a file called **firstrun.sh** placed in the root of the boot partition. Imager generates this file automatically when you use Advanced Options. If you are scripting image preparation, you can generate this file yourself. The structure is a shell script that runs once on first boot and then deletes itself. It writes configuration to /etc, sets the hostname, creates the user, and enables SSH.

A minimal firstrun.sh that enables SSH and creates a user looks like this:

For most single-device setups, Imager's Advanced Options produce a correct firstrun.sh with no manual work. Manual firstrun.sh editing is worth learning only if you are imaging devices programmatically.

Wi-Fi Configuration

On Bullseye and earlier, Wi-Fi was configured by placing a file named **wpa_supplicant.conf** in the root of the boot partition. On first boot, the OS copied it to /etc/wpa_supplicant/. That file method is not supported in Bookworm.

On Bookworm, Wi-Fi credentials are written into **/etc/NetworkManager/system-connections/** as a .nmconnection file. Imager generates this correctly when you enter SSID and password in Advanced Options. If writing manually, the file format is a standard NetworkManager keyfile with sections for [connection], [wifi], and [wifi-security].

For wired Ethernet deployments, none of this is necessary. Plug in the cable and the Pi will obtain an IP via DHCP without any pre-configuration. Wired is simpler and more reliable for fixed installations.

Finding the Pi on the Network

Once the Pi boots, you need its IP address to connect. Three practical approaches:

Once you have the IP, connect with `ssh username@192.168.1.x` or `ssh username@myhostname.local`. If you used a public key during image setup, no password prompt appears. For more detail on SSH connection options and key management, see [SSH for Raspberry Pi: Headless Access in the Field](ssh-raspberry-pi-headless-field-access).

Post-Boot Configuration Checklist

First boot configuration gets the Pi onto the network. A small amount of additional work makes it suitable for unattended operation.

For devices that will be physically inaccessible after deployment, remote access planning matters before the unit ships. [How to SSH to Raspberry Pi Without a Monitor](how-to-ssh-raspberry-pi-no-monitor) covers the access patterns in more depth, and [Raspberry Pi SSH Access for Unattended Remote Nodes](raspberry-pi-ssh-unattended-remote-nodes) addresses what happens when the network environment at the deployment site is not fully under your control.

For Production Deployments

The process above works reliably for development and small-scale deployments on standard Raspberry Pi boards. For production infrastructure, particularly devices that run continuously in locations without regular physical access, the hardware platform matters as much as the software configuration.

When moving to the Compute Module 4 or CM5 for production work, the carrier board determines whether headless operation is practical at scale. Poepi is a CM4/CM5 carrier board designed specifically for unattended headless deployments, delivering both power and network over a single Ethernet cable so there is no separate power supply to fail or disconnect.

Regardless of hardware, the core principle is the same: configuration embedded before first boot is more reliable than any first-run manual step. Devices that boot correctly the first time, recover from power loss without intervention, and accept SSH connections from a known key are the ones that stay in service.

FAQ

Does Raspberry Pi OS Bookworm still support the empty 'ssh' touch file?

No. The empty ssh file in the boot partition was removed in Bookworm. Use Raspberry Pi Imager's Advanced Options or a manually prepared firstrun.sh to enable SSH before first boot.

Can I configure headless setup on a Pi that has already been booted once?

Yes. SSH can be enabled post-boot by running `sudo systemctl enable --now ssh` over an existing connection, or by booting with a monitor and keyboard once to enable it. The pre-boot method is only necessary when you have no other access path.

My Pi is not showing up on the network after first boot. What should I check?

Confirm the SSID and password are correct if using Wi-Fi. Check that the image was written completely by verifying it in Imager. Try a wired connection to rule out wireless issues. Confirm the Pi's power supply delivers adequate current, since a brownout during boot can produce silent failures.

What username does Raspberry Pi OS create by default now?

Since Bullseye, the default 'pi' user is no longer created automatically. You must set a username and password (or public key) in Imager's Advanced Options or in firstrun.sh. There is no fallback default credential.

How do I add my SSH public key during headless setup?

In Imager's Advanced Options, there is a field to paste your public key directly. If editing manually, write the key into /home/username/.ssh/authorized_keys inside firstrun.sh, then set ownership and permissions correctly (700 on .ssh, 600 on the file).

Is it safe to keep SSH enabled permanently on a field-deployed Pi?

It is standard practice, but key-based authentication should replace password authentication before the device leaves the bench. Disable PasswordAuthentication in sshd_config and consider restricting the SSH service to a specific network interface if the device has multiple network paths.

What is the difference between Raspberry Pi OS Lite and the full desktop image for headless use?

Lite has no desktop environment, lower memory usage, and faster boot times. For any headless deployment, Lite is the correct choice. The desktop image wastes resources on a display server that will never render anything.