Headless Mode Install: Raspberry Pi Zero W

Headless Mode

Headless Mode?

Headless Mode on a Raspberry Pi Zero W is when it runs without an attached screen, keyboard or mouse. In this article, we will install the image and pre-configure it for your Wi-Fi network and SSH access. We will also do some basic configuration and get the OS up to date.

What is a Raspberry Pi Zero W?

A Raspberry Pi Zero W (we’ll just call it a Pi Zero from now on), is a low power single board computer. It was originally meant as a tool to teach programming. But as you’ll see here, it can easily be used for more permanent purposes. If you’d like to know more you can check out its page on the Raspberry Pi Foundation website.

Installation

This article has been updated to confirm that these install procedures are still current as of March 1, 2020. It was tested with Raspbian Buster Lite, version February 2020 2020-02-13

Software Pre-requisites

balenaEtcher

In order to get the operating system image onto your microSD card, you need software capable of converting the image to an appropriate format. The software recommended by the Raspberry Pi team is balenaEtcher. Versions are available for Windows, Mac and Linux. Download the version appropriate for your operating system and install it as you normally would.

Raspian Lite Download

Head to the Raspian Download Page and get the latest Raspian Lite image.
https://www.raspberrypi.org/downloads/raspbian/
** You don’t need to unzip the image as balenaEtcher will do that for you.

Flashing the microSD Card

To flash the image to your microSD card involves very few steps.

  1. Put your microSD card into whatever adaptor is needed to connect to your computer and plug it in.
  2. Open balenaEtcher:
    1. Select image – browse to the zip file you downloaded earlier
    2. Select target – it will generally find the microSD card automatically
    3. Click Flash!
      It will proceed with flashing and then validating.
    4. When Flash Complete! appears you can close balenaEtcher

After flashing completes it will often eject/dismount the card. If you can’t see it remove the card and plug it back in.

Enabling SSH

To increase security SSH is not enabled by default in current versions of Raspbian. But in order to use headless mode, we will need it. This is a very simple process. We simply need to create a file called ssh on the boot volume of the microSD card.

  • In the text editor of your choice. Create a new file containing a single space.
  • Save this file to the root of the boot volume as ssh.
    • Make sure it is in lower-case and has no extension.

Configure your Wi-Fi information

You need to configure Wi-Fi before the first startup so you can connect with ssh. To do this, we need to add a second file to the root of the boot volume. Once open the text editor of your choice and create a file called wpa_supplicant.conf. Paste the contents of the code box below into the file.

Adjust the country code as appropriate for your region. A list is available from Aruba Networks.
Adjust the ssid and psk to match your Wi-Fi network and password. Both are case sensitive.

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

network={
    ssid="NETWORK-NAME"
    psk="NETWORK-PASSWORD"
}

Finalizing the Install

At this point, you can now remove the microSD card from your computer. I recommend you eject or dismount the card in the manner specified for your operating system. This is because microSD cards are more prone to corruption and damage than your average flash drive.

Insert the microSD card into the Pi Zero and install it in a case if you have one. A case is highly recommended so as not to short out the board. You are now ready for the first boot.

First Boot

Connect your assembled Pi Zero to the power cord. The power port is the micro-USB port closest to the end of the device.
The first boot can take a long time potentially even a few minutes.

Getting Connected

You will now need to determine the IP address of your Pi Zero. Initially, the hostname is raspberrypi.local Depending on your router you can usually look it up in your DHCP leases.

Alternatively, you can take advantage of the fact that Raspbian comes pre-configured to use mDNS. macOS computers have this capability builtin. For Windows computers, you can install Bonjour Print Services. For Linux computers, the Avahi tools may be pre-installed. If not, if your computer is Debian/Ubuntu derived it can be installed by running.

sudo apt-get install avahi-daemon avahi-autoipd

For Fedora / CentOS based computers.

sudo yum install avahi-daemon avahi-autoipd

If you’ve gone the mDNS route you should now be able to resolve the name raspberrypi. local

Connecting in Headless Mode with SSH

Now that you have determined that your Pi Zero is online, it should be ready to go in Headless Mode.
The default username is pi
The default password is raspberry

  • On a Linux box, the SSH client is available from the command line.
  • With macOS SSH is available in the Terminal application
  • In Windows 10 builds from 2018 or newer SSH is built-in to Powershell and automatically enabled
    • However, for other Windows 10 versions, it can be enabled in Manage Optional Features
    • Otherwise, you can download Putty which is the most commonly used client for Windows

For any of the integrated clients, you can now connect with either.

ssh [email protected]
or
ssh pi@<ip address>

At this point, you will be prompted for the password. Once entered you should be at the command prompt. Congratulations your Pi Zero is running in Headless Mode.

Additional Configuration

Changing the IP to Static

If you are planning to use your Pi Zero to host services like web servers. Consequently. you will want to change the IP from dynamic to static. For this, you have two options.
Firstly, you can create a reservation in your DHCP server. This is usually on your router. The procedure for this varies from manufacturer to manufacturer. The downside to this option is that if you ever replace your router all your reservations may be lost as the Pi still technically has a dynamic IP.
Otherwise, the option is to configure the Pi Zero to have a real static IP. The procedure for this is documented in our article Static IP Configuration for your Raspberry Pi

Raspi-config Options

Updating the Hostname

You should change the hostname from the default of raspberry. Otherwise, if you ever set up a second Raspberry Pi you will have devices with conflicting hostnames. Launch raspi-config

sudo raspi-config

Choose Network Options then Hostname and enter a new name. You can use a short descriptive name, like webserver1. Optionally, you can invent a naming scheme more to your liking. Don’t exit yet there are more options to change.

Expanding the File System

If you have installed anything large than a 2gb MicroSD card you will want to expand the file system to make it all available. If you have closed raspi-config relaunch it otherwise, choose Advanced Options from the main menu. Then Expand Filesystem. Once complete it will return you to the main menu. Once again don’t exit as there is one more change to be made.

Change the Default Password

While this step is optional, it is recommended as leaving the default password in place can be a security risk. Choose Change User Password from the main menu. Choose OK on the next screen and you will be dropped to a command prompt. Now enter a new password then confirm. You will be informed if the change was successful.

Exit and Reboot

Now choose Finish and then Yes to reboot.

Your SSH session will disconnect. Give the system time to reboot and reconnect with the new hostname or IP address. Enter the username pi and if you changed it the new password.

System Updates

Now that you are up and running you should perform system updates. Even if the image version you downloaded is only a few weeks old there are nearly always a few updated packages. By keeping current you will always have the newest security packages.

sudo apt-get update -y
sudo apt-get upgrade -y

Depending on what updates are available you may be asked to reboot once complete.

Congratulations

You now have a running and updated Pi Zero running in Headless Mode. Ready to be used for all sorts of projects and uses.

You may also like...