How to set up Raspberry Pis as headless servers

2 minute read

The steps laying out here are distilled from my own trial and error. Hope it will help you!

Download Raspbian image

Because I run servers headless, there is no need to use a full Desktop version of Raspbian. I download its lite version image here: https://www.raspberrypi.org/downloads/raspbian/.

Load Raspbian image to a SD card

I find a program called etcher is extremely reliable and runs on multiplatform (Linux, Windows, and Mac OS) without the need to install. Download the proper version for your desired OS at: https://www.balena.io/etcher/. Etcher

Set up wifi

The purpose of this setup is for your Raspberry Pi can connect to a wifi network on its very first boot, saving you time to connect it to a LAN cable and edit the wifi interface file.

Add a wpa_supplicant.conf file to the /boot directory (the directory is in fat32 format so it is easy to show up on Windows too).

The content of the file:

country=US # Your 2-digit country code
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
    ssid="YOUR_NETWORK_NAME"
    psk="YOUR_PASSWORD"
    key_mgmt=WPA-PSK
}

Raspbian will move it to the proper place at /etc/wpa_supplicant/ at the first boot and automatically connect to the wifi specified in the file.

Note: It is not me to invent the method, I read it somewhere on stackexchange when my HDMI cable broke and could not access to a LAN port. Have been using it successfully ever since from Stretch to Buster.

Enable SSH

Create a empty file name ssh, without any extension, in the /boot directory. Raspbian will detect it during the first boot and enable SSH.

Note: I found it here: Raspberry Pi’s documentation on SSH.

Scan for Raspberry Pi’s IP on your network

I have setup fix IPs for every of my Raspberry Pi depending on their Mac addresses or have them send me their IP to my email everytime they connected to a new network as in this post:Use mutt email manager/. So this is only for the first time use.

I am using nmap to scan the IPs in my network with this command:

sudo nmap -sP 192.168.1.0/24

Where 192.168.1.0/24 will be your all network gateways (the IPs of devices that grant IPs).

Note: Credit to the answer here: Find Raspberry PI address on local network.

My Raspberry Pi show up like this:

MAC Address: X8:XX7:XB:6X:X1:XX (Raspberry Pi Foundation)
Nmap scan report for 192.168.1.XXX

Its IP will be 192.168.1.XXX.

If your Debian/ Ubuntu system do not come with nmap line mine, install it using below command:

sudo apt-get install nmap

Leave a comment