Back to Blog

Setting Up Raspberry Pi OS Lite

Viktor Vasylkovskyi

Previous: Hardware Requirements

Once your Raspberry Pi hardware is ready, the next major step is configuring the SD card with the operating system. In this guide, we'll walk through how to flash Raspberry Pi OS Lite to an SD card and configure it for headless operation with SSH access.

Raspberry Pi OS Lite is perfect for server applications because it has no desktop environment - just a lightweight command-line interface that uses minimal system resources and leaves more CPU and RAM available for your applications. Let's dive in!

Github Repository

All the Ansible configurations and setup scripts from this guide series are available in https://github.com/IaC-Toolbox/iac-toolbox-raspberrypi. Feel free to clone it and follow along!

┌──────────────────────────────────────────────────────────────┐
│              HEADLESS RASPBERRY PI SETUP FLOW                │
└──────────────────────────────────────────────────────────────┘

    ┌─────────────────┐
    │  Your Mac/PC    │
    │  (Control Node) │
    └────────┬────────┘

             │ 1. Flash OS with Raspberry Pi Imager
             │    • Enable SSH
             │    • Add public key
             │    • Configure WiFi

    ┌─────────────────┐
    │   microSD Card  │
    │   (OS Lite 64)  │
    └────────┬────────┘

             │ 2. Insert & Boot

    ┌─────────────────┐
    │  Raspberry Pi   │
    │  • Boots up     │
    │  • Connects     │
    │    to WiFi      │
    └────────┬────────┘

             │ 3. SSH Connection
             │    ssh pi@raspberrypi.local

    ┌─────────────────┐
    │  Terminal       │
    │  You're in! 🎉  │
    └─────────────────┘

Step 1: Installing Raspberry Pi OS Lite

Raspberry Pi OS Lite (64-bit): Download from the official Raspberry Pi downloads page. Make sure the OS version matches your hardware's architecture (ARM64 for Raspberry Pi 4B).

Flash the OS Image

  1. Download and install Raspberry Pi Imager.
  2. Open Raspberry Pi Imager.
  3. Choose the OS: Raspberry Pi OS Lite (64-bit)
  4. Select your SD card as the storage device.
  5. Click the settings icon (⚙️) or press CMD + Shift + X to open advanced options.

Step 2: Customize the OS for Headless Access

Since OS Lite has no graphical interface, we need to enable SSH and configure credentials ahead of time - before the first boot. This is where the magic happens!

Enable SSH with Public Key Authentication

In the advanced settings menu:

  • ✅ Enable SSH
  • 🔘 Select "Only allow public-key authentication"

This is much more secure than password authentication and will allow you to connect without typing a password every time. Win-win!

Creating SSH Key Pair

If you don't already have an SSH key pair, fear not! We'll create one now on your Mac or Linux machine:

  1. Generate an SSH key pair:
ssh-keygen -t ed25519 -C "your_email@example.com"

Press Enter to accept the default file path (~/.ssh/id_ed25519) and choose a passphrase if desired (or just press Enter twice to skip it for now).

  1. Copy the contents of your public key:
cat ~/.ssh/id_ed25519.pub
  1. Paste the output into the SSH public key field in the Raspberry Pi Imager settings.

Define Username and Network

Back in the Raspberry Pi Imager advanced settings:

  • Set a username (e.g., pi or your preferred username)
  • Configure wireless LAN settings: Enter your WiFi SSID, password, and country code
  • Set a hostname for easy network discovery (e.g., raspberrypi)

Click Save, then Write to flash the SD card. This will take several minutes.

Step 3: Boot the Raspberry Pi

Now for the moment of truth:

  1. Insert the SD card into your Raspberry Pi
  2. Connect the power supply

The device will boot automatically and connect to your WiFi network. Since it's headless, you won't see anything visually—your next interaction will be via SSH.

Step 4: Connect to the Pi via SSH

Wait about 30-60 seconds for the Pi to boot and connect to the network. Then connect via SSH:

  1. Ensure your Mac is on the same network as the Raspberry Pi.

  2. Add your private key to the SSH agent (if you haven't already):

# Enable the SSH agent
eval "$(ssh-agent -s)"

# Add your private key to the agent
ssh-add ~/.ssh/id_ed25519
  1. Connect to your Raspberry Pi via hostname or IP:
ssh pi@raspberrypi.local

Replace pi with the username you configured, and raspberrypi.local with your chosen hostname.

If you configured everything correctly, you'll be logged in without needing a password!

Troubleshooting

Can't connect to raspberrypi.local?

Your network might not support mDNS (multicast DNS). Try finding the IP address directly:

  1. Check your router's connected devices list, or
  2. Use a network scanner like nmap:
# Scan your local network (adjust IP range as needed)
nmap -sn 192.168.1.0/24

Then connect using the IP address directly:

ssh pi@192.168.1.100

Next Steps

And that's a wrap! You now have a headless Raspberry Pi accessible via SSH. Having configured many Raspberry Pi devices in the past, I can confidently say that manual configuration from here is time-consuming and repetitive. In the next section, we'll use Ansible to automate the installation of essential software like Docker, Python, and system utilities. Continue reading!


Previous: Hardware Requirements | Next: Ansible Base Software Setup