How to Set Up Raspberry Pi Without Monitor (Headless Setup)
To set up a Raspberry Pi without a monitor, prepare the SD card by enabling
SSH and configuring wpa_supplicant.conf on the boot partition. Then, connect the Pi to power and network, and access it remotely via SSH from your computer.Syntax
To set up Raspberry Pi headlessly, you need to prepare the SD card with two key files on the boot partition:
ssh: an empty file to enable SSH access.wpa_supplicant.conf: a file containing Wi-Fi network details.
After inserting the SD card into the Pi and powering it on, you can connect remotely using SSH.
bash
touch /path/to/boot/ssh cat > /path/to/boot/wpa_supplicant.conf <<EOF country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="YourWiFiSSID" psk="YourWiFiPassword" key_mgmt=WPA-PSK } EOF
Example
This example shows how to enable SSH and configure Wi-Fi on the Raspberry Pi SD card from a Linux or macOS computer before first boot.
bash
# Mount the SD card boot partition (replace /dev/sdX1 with your device) sudo mount /dev/sdX1 /mnt # Enable SSH by creating an empty file sudo touch /mnt/ssh # Create Wi-Fi config file sudo tee /mnt/wpa_supplicant.conf > /dev/null <<EOF country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="HomeNetwork" psk="SuperSecretPassword" key_mgmt=WPA-PSK } EOF # Unmount the SD card sudo umount /mnt # After inserting the SD card into the Pi and powering it on, find its IP address and connect: ssh pi@raspberrypi.local # Default password: raspberry
Output
pi@raspberrypi:~ $
Common Pitfalls
Common mistakes when setting up Raspberry Pi without a monitor include:
- Not creating the
sshfile, so SSH remains disabled. - Incorrect Wi-Fi details or wrong country code in
wpa_supplicant.conf, causing network connection failure. - Using Windows Notepad to create
wpa_supplicant.confwhich may add hidden extensions or wrong line endings. - Trying to SSH before the Pi has fully booted and connected to the network.
iot_protocols
Wrong way: # Using Notepad and saving as wpa_supplicant.conf.txt disables Wi-Fi Right way: # Use a plain text editor and save exactly as wpa_supplicant.conf with Unix line endings
Quick Reference
Summary tips for headless Raspberry Pi setup:
- Always enable SSH by adding an empty
sshfile to the boot partition. - Configure Wi-Fi with a properly formatted
wpa_supplicant.conffile. - Use tools like
ssh pi@raspberrypi.localor find the Pi's IP on your router to connect. - Default username is
piand password israspberry.
Key Takeaways
Enable SSH by placing an empty 'ssh' file in the SD card boot partition before first boot.
Configure Wi-Fi by creating a correctly formatted 'wpa_supplicant.conf' file with your network details.
Use SSH from your computer to connect to the Raspberry Pi once it boots and joins the network.
Avoid Windows editors that add extensions or wrong line endings to configuration files.
Default Raspberry Pi login is username 'pi' and password 'raspberry'.