July 7, 2019

Headless Raspberry Pi Setup - Wifi

Raspberry Pi Headless Setup - how to get started with ssh and wifi. It's easy and takes less than five minutes.

Headless Raspberry Pi Setup - Wifi

The Goal: Setup Headless Access to your Raspberry Pi over Wifi

This guide is designed to help you setup your Raspberry Pi up headlessly over wifi using your Raspberry Pi's built in wifi.

This will work for the following Raspbery Pi models:

This might also work for other Raspberry Pi models if you have installed a supported Wifi device, however that is a different beast all together. If this is what you're trying to do and would like me to write about that - let us know in the comments section below.

Credit: Raspberry Pi Models Comparison Chart


So, basically, we need to do three things here:

  1. Image your disk
  2. touch /boot/ssh
  3. configure /boot/wpa_supplicant.conf

Image your disk:

  1. Download the latest Raspbian image. Since this is a headless setup, you only need the "lite" version.

    Raspbian Buster Lite: Torrent Download | Direct Download

    (Above linkes are copied from the Raspberry Pi Download's page)

  2. Use Etcher to image your Micro SDHC Card. it takes less than 5 minutes to image a disk with a full Raspbian Buster Lite

  3. Mount the SDHC Card to your computer again after imaging. (unplug the Micro SDHC and plug it back in to your computer)


Enable ssh:

Create an empty file named ssh in the /boot partition

touch /Volumes/boot/ssh

On a Mac, in a bash terminal, running touch /Volumes/boot/ssh "creates" the ssh file. If you're on Windows, simply open the disk labeled "boot" and create an empty text file named ssh.


Configure wpa_supplicant.conf:

Create a file named wpa_supplicant.conf in the /boot partition and configure it with the needful wifi settings:

vi /Volumes/boot/wpa_supplicant.conf

(create/open wpa_supplicant.conf in your favorite editor, then change the country code and wifi settings to match your needs.)

# Example wpa_supplicant.conf
# Documentation:
# https://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf

# Leave these two lines alone:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

# Edit your country:
country=US

# Configure your wifi network:
network={
  ssid="Your_Wifi_SSID"
  psk="Super_Secret_Passphrase"
}

If your wifi network requires a more complicated setup, the documentation on wpa_supplicant.conf is quite thorough.


Done! - unmount, and bootup.

And you're done. It's that easy. Unmount your disk, pop it into your pi and give it power to boot up.

You might notice after booting up that the /boot/wpa_supplicant.conf has been "consumed" and moved to /etc/wpa_supplicant/wpa_supplicant.conf.

The first boot up takes a moment longer than usual because it's resizing the partitions to fill the SDHC card... So, after waiting a moment you should be able to run:

1. Remove any stail entries in your ~/.ssh/known_hosts file.

ssh-keygen -R raspberrypi.local

2. SSH into your newly configured, headless Raspberry Pi

ssh pi@raspberrypi.local

Headless? - sure, but not clueless...

Now that we're here, I usually do a few things right off the bat.

1. Test the internet connection

ping 8.8.8.8

2. Change the pi password, locale, hostname, timezone, expand file system (just in case?). You can do all of this inside of

sudo raspi-config

3. After a reboot, I then run

sudo apt update

Right now on the current release of Raspbian you will notice that you get this message:

E: Repository 'http://raspbian.raspberrypi.org/raspbian buster InRelease' changed its 'Suite' value from 'testing' to 'stable'
N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details.
Do you want to accept these changes and continue updating from this repository?

type y and hit enter.

This is happening because Debian Buster and Raspbian Buster are both so new. Until Raspbian releases a new image to download with the Suite already set as Stable people are going to have to agree to this change. Just say yes and move on.

sudo apt update
Get:1 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
Get:2 http://archive.raspberrypi.org/debian buster InRelease [25.1 kB]
E: Repository 'http://raspbian.raspberrypi.org/raspbian buster InRelease' changed its 'Suite' value from 'testing' to 'stable'
N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details.
Do you want to accept these changes and continue updating from this repository? [y/N] y
Get:3 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages [13.0 MB]
Get:4 http://archive.raspberrypi.org/debian buster/main armhf Packages [205 kB]
Get:5 http://raspbian.raspberrypi.org/raspbian buster/contrib armhf Packages [58.7 kB]
Fetched 13.3 MB in 37s (362 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
28 packages can be upgraded. Run 'apt list --upgradable' to see them.

4. Now upgrade

sudo apt upgrade
sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  bind9-host bzip2 cron dmsetup libbind9-161 libbz2-1.0 libdevmapper1.02.1 libdns-export1104 libdns1104 libexpat1 libgssapi-krb5-2
  libisc-export1100 libisc1100 libisccc161 libisccfg163 libk5crypto3 libkrb5-3 libkrb5support0 liblwres161 libraspberrypi-bin
  libraspberrypi-dev libraspberrypi-doc libraspberrypi0 libwbclient0 nano raspberrypi-bootloader raspberrypi-kernel raspi-config
28 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 97.9 MB of archives.
...
... [a bunch of stuff will scroll by you now...]
...
Setting up libk5crypto3:armhf (1.17-3) ...
Setting up libisc-export1100:armhf (1:9.11.5.P4+dfsg-5.1) ...
Setting up libraspberrypi0 (1.20190620+1-1) ...
Setting up nano (3.2-3) ...
Setting up libisccc161:armhf (1:9.11.5.P4+dfsg-5.1) ...
Setting up libkrb5-3:armhf (1.17-3) ...
Setting up raspi-config (20190620) ...
Setting up libdns-export1104 (1:9.11.5.P4+dfsg-5.1) ...
Setting up libraspberrypi-doc (1.20190620+1-1) ...
Setting up libraspberrypi-bin (1.20190620+1-1) ...
Setting up libgssapi-krb5-2:armhf (1.17-3) ...
Setting up libraspberrypi-dev (1.20190620+1-1) ...
Setting up libdns1104:armhf (1:9.11.5.P4+dfsg-5.1) ...
Setting up libisccfg163:armhf (1:9.11.5.P4+dfsg-5.1) ...
Setting up libbind9-161:armhf (1:9.11.5.P4+dfsg-5.1) ...
Setting up bind9-host (1:9.11.5.P4+dfsg-5.1) ...
Setting up libdevmapper1.02.1:armhf (2:1.02.155-3) ...
Setting up dmsetup (2:1.02.155-3) ...
Processing triggers for install-info (6.5.0.dfsg.1-4+b1) ...
Processing triggers for libc-bin (2.28-10+rpi1) ...
Processing triggers for systemd (241-5+rpi1) ...
Processing triggers for man-db (2.8.5-2) ...

Done

... now the fun begins


Photo Credit: Original Photo by Valeriy Kryukov on Unsplash, bubble designed by macrovector_official / Freepik