Set up a Raspberry Pi Zero headless
By Leo Gaggl
If you are using the GUI (Raspian full download) and want to connect your RPi Zero to a keyboard and monitor there are probably easier ways to do this. These notes are for people that want to use a headless (no monitor and GUI) setup ready to connect to your RPi after first boot via SSH from another terminal.
wget -O raspbian-lite-latest.zip https://downloads.raspberrypi.org/raspbian_lite_latest
Download link: https://www.raspberrypi.org/downloads/raspbian/
Write Image to SD Card
dd bs=4M if=2017-08-16-raspbian-stretch-lite.img of=/dev/sdb
After this step there should be 2 additional mounts (if not mount the 2 SD card partitions manually).
Set up network interfaces
Create a new config file for the wireless interface.
cd etc/network/interfaces.d/<br></br>vim wlan0.conf
Add the following to the new file (if you want to use DHCP – change to static if you want to fix the IP):
auto wlan0<br></br>allow-hotplug wlan0<br></br>iface wlan0 inet dhcp<br></br> wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Set up connection details for local wireless network
vim etc/wpa_supplicant/wpa_supplicant.conf
Check the file and ensure the network settings are as per the Wireless Network you are connecting to.
country=AU<br></br>ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev<br></br>update_config=1<br></br>network={<br></br> ssid="SSID"<br></br> psk=HASHED_PSK_VALUE<br></br>}
You could use the clear-text PSK passphrase but I prefer not to do that in configuration files. Create a PSK hash using ‘wpa_passphrase‘ this older article
There could be other config values you might need depending on the network you are connecting to. More info: https://linux.die.net/man/5/wpa_supplicant.conf.
Ensure there are DNS Servers configured
sudo vim etc/resolv.conf
Add the following to the new file (or your own nameservers):
# Google's public DNS servers<br></br>nameserver 8.8.8.8<br></br>nameserver 8.8.4.4
Enable SSH Access
Create an ssh empty file in the mounted boot partition. This is necessary to enable SSH access as SSH is by default disabled on more recent versions of Raspbian.
cd boot/<br></br>sudo touch ssh
Boot RPi
Boot the Rpi by powering up and after ~30secs you should be able to connect to the IP assigned. Check your router or ise ‘nmap’ or similar to check the assigned IP:
sudo nmap -p22 -sV 10.1.1.0/24
Default login details are
UID: pi
PWD: rasbperry
My normal further setup steps for RPi 3 are here.
EDIT [2017-08-21]: One of the things necessary on later RPi’s is to turn off power saving mode on the WLAN interface.
sudo iw dev wlan0 set power_save off