Headless Raspberry Pi Zero

October 01, 2016

I finally picked up my first Raspberry Pi, but I have neither a keyboard nor an HDMI display to set it up. Fortunately, these aren't needed.

These are the steps I carried out to get it up and running on my network.

Gather the parts

  1. Rapberry Pi Zero
  2. 8 GB MicroSD card
  3. Miniature WiFi module
  4. Tiny OTG adapter

Download the operating system

Head over to the Raspbian section of the Raspberry Pi site, and grab Raspbian Lite. At the time of writing, the latest version is Raspbian Jessie, and is available as a .zip file.

$ wget https://downloads.raspberrypi.org/raspbian_lite_latest \
  -O raspbian_lite_latest.zip
$ unzip raspbian_lite_latest.zip

Install the operating system

Using a card reader, connect the MicroSD card to your computer.

Optionally, check dmesg to find its device name.

$ dmesg | grep -i attached
[170252.446534] sd 12:0:0:0: [sdb] Attached SCSI removable disk

On my system, the MicroSD card is attached as /dev/sdb.

Once you're certain which device is the MicroSD card, write Raspbian to it using dd.

$ sudo dd bs=4M status=progress \
  if=2016-09-23-raspbian-jessie-lite.img of=/dev/sdb

Configure the wireless network

The MicroSD card should now have two partitions: a boot partition at /dev/sdb1 and a root partition at /dev/sdb2. Mount the root partition.

$ udisksctl mount -b /dev/sdb2
Mounted /dev/sdb2 at /run/media/james/raspberry
$ cd /run/media/james/raspberry

Configure the wireless card to connect automatically using DHCP.

$ sudo sed -i \
  's/iface wlan0 inet manual/auto wlan0\niface wlan0 inet dhcp/g' \

Configure the wireless card to authenticate with your network. I use a conventional WPA2 setup with a pre-shared key.

$ cat << EOF |
  sudo tee --append etc/wpa_supplicant/wpa_supplicant.conf > /dev/null
> network={
>         ssid="MyWiFiName"
>         psk="MyWiFiPassword"
>         proto=RSN
>         key_mgmt=WPA-PSK
>         pairwise=CCMP
>         auth_alg=OPEN
> }

Unmount the MicroSD card, and remove it from your computer.

$ cd
$ udisksctl unmount -b /dev/sdb2
Unmounted /dev/sdb2.

Fire it up

Pop the MicroSD card into the Raspberry Pi, connect the WiFi module to the USB port, and connect a powered USB source to the PWR IN port.

Pi Zero all hooked up
Pi Zero all hooked up

Get connected

Wait a moment for the Raspberry Pi to boot up, then scan for it on your network. Look for the hostname raspberrypi with port 22 exposed.

$ nmap | grep -A 4 raspberrypi
Nmap scan report for raspberrypi (
Host is up (0.040s latency).
Not shown: 999 closed ports
22/tcp open  ssh

To connect to it, use the username pi, and the password raspberry.

$ ssh pi@
pi@'s password:

pi@raspberrypi:~ $

Go forth and Pi

This user has sudo, and can be used for any system administration you need.

pi@raspberrypi:~ $ sudo id
uid=0(root) gid=0(root) groups=0(root)

Make sure to change the password to something other than raspberry.

pi@raspberrypi:~ $ passwd
Changing password for pi.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully