0
0
Raspberry Piprogramming~5 mins

Headless deployment setup in Raspberry Pi

Choose your learning style9 modes available
Introduction

Headless deployment lets you use your Raspberry Pi without a monitor or keyboard. You control it remotely, saving space and making setup easier.

You want to set up a Raspberry Pi in a hard-to-reach place.
You don't have a spare monitor or keyboard for the Raspberry Pi.
You want to manage multiple Raspberry Pis from one computer.
You want to save power and space by not connecting extra devices.
You want to automate software installation and updates remotely.
Syntax
Raspberry Pi
1. Prepare Raspberry Pi OS image on SD card.
2. Enable SSH by creating an empty file named 'ssh' (no extension) in the boot partition.
3. Configure Wi-Fi by adding a 'wpa_supplicant.conf' file in the boot partition with network details.
4. Insert SD card into Raspberry Pi and power it on.
5. Connect to Raspberry Pi via SSH using its IP address.

The 'ssh' file has no extension and no content; it just enables SSH on boot.

The 'wpa_supplicant.conf' file must have correct Wi-Fi details and proper formatting.

Examples
This enables SSH access on Raspberry Pi startup.
Raspberry Pi
Create empty file named 'ssh' in the boot folder:
touch /path/to/boot/ssh
This file connects your Raspberry Pi to your Wi-Fi network automatically.
Raspberry Pi
Example 'wpa_supplicant.conf' content:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YourWiFiName"
    psk="YourWiFiPassword"
    key_mgmt=WPA-PSK
}
Replace '192.168.1.100' with your Pi's IP address to connect remotely.
Raspberry Pi
SSH into Raspberry Pi:
ssh pi@192.168.1.100
Sample Program

This script enables SSH and sets Wi-Fi on the Raspberry Pi SD card. After running it, insert the SD card into your Pi and power it on. Then connect via SSH.

Raspberry Pi
# This is a shell script example to prepare SD card for headless setup

BOOT_MOUNT=/media/$USER/boot

# Enable SSH
sudo touch $BOOT_MOUNT/ssh

# Create wpa_supplicant.conf with Wi-Fi details
cat <<EOF | sudo tee $BOOT_MOUNT/wpa_supplicant.conf
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="HomeWiFi"
    psk="password123"
    key_mgmt=WPA-PSK
}
EOF

# Inform user
echo "SD card prepared for headless Raspberry Pi setup."
OutputSuccess
Important Notes

Make sure your computer can read the Raspberry Pi boot partition (usually FAT32).

Find your Raspberry Pi's IP address using your router or network scanning tools.

Default username is usually 'pi' and password 'raspberry' unless changed.

Summary

Headless setup lets you control Raspberry Pi without extra devices.

Enable SSH by adding an empty 'ssh' file to the boot partition.

Configure Wi-Fi by adding 'wpa_supplicant.conf' with your network info.

Connect remotely using SSH once the Pi boots up.