← blog

Setting up a headless Raspberry Pi Zero W

Last week I purchased a couple of Raspberry Pi Zero Ws and I set one up today to run headless. Setting up SSH on pi can be pretty tricky to do if you don't want to bother with all the peripherals. Pi Zeros only have 2 micro usb ports - one for power and one for usb - so you would need an otg hub in order to extend your usb functions. I don't have a hub so I wanted to SSH directly into the Pi for the first time. I'll outline the process that I had here.

Parts list:

  • Raspberry Pi Zero W
  • 32 gb micro sd card
  • Micro USB Cable


  • Ubuntu 16.04
  • Etcher

Step 1 - Download the Linux Image

First I downloaded the Raspberry Pi Stretch IMG. I found that Etcher is the easiest way to flash my SD with the Raspian OS. The official Raspberry Pi has detailed instructions here.

Step 2 - Mount it locally

After installing the raspberry pi os you can conceivably just plug it into and power your Pi. BUT you need to have a monitor, keyboard, mouse, and an endless amount of cables to run them. So you have to change a lot of files before you can boot and access it through wifi.

The easiest way to remount the SD drive is to unplug and plug it back into my laptop. At this point I can see the drive in my Ubuntu file manager, but if its not showing you can find it with the command df -h. Its easiest to find it by the disk size. My card is mounded on /dev/sdc1.

Step 3 - Configure WiFi

Because I want to start right into ssh I have to change some files before starting on the Pi. I'm changing the file at etc/network/interfaces.

In order to change the files you have to run at the administrator level. Use the command sudo nano etc/network/interfaces and add:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Set up the wifi connection and passkey by editing etc/wpa_supplicant/wpa_supplicant.conf.


  ssid="network name"
  psk="network password"

On newer versions of Raspian the SSH is disabled at default. Enable ssh in the boot directory. Find the /boot directory and create the ssh file by touch ssh.

If you're using Raspian Stretch, the latest version of Raspian you have to include the full wpa_supplicant. According to Medium user Antonio Armada you don't have to change the interface file. Instead in the boot directory create a wpa_supplicant.conf file with:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


Because I'm at school where there are hundreds of devices connected to the wifi, I think the easiest way is to connect to your phone's hotspot because you will need the Pi's IP address in order to ssh.

Step 4 - Boot the Pi

At this point the pi will boot and connect to wifi, but you have to locate the IP address. Locate the ip addresses connected to the phone by using nmap.

Run ip a to find the address of the phone's hotspot. Then run sudo nmap -p22 -sV It should return all the devices on the network. Now you can ssh into that address.

The default hostname is raspberrypi so you can ssh by pi@raspberrypi.local and the default password is raspberry.

[user@linux ~]# ssh pi@
pi@raspberrypi:~ $

You're in the pi! :100:

Now the first thing I would do is change the password to secure the pi. Run: passwd

Then I would probably update the software on the pi by:

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

Extra stuff

To speed up the device I suggest changing some Raspberry Pi settings by running sudo raspi-config. Here you can change the boot to multi-user mode(disable GUI on boot) if you plan on running it completely headless. Change the boot to multi-user.

I also disable the HDMI.

After all that hard work its fun to change the boot message for when you boot the pi. You can change it by nano /etc/motd and delete the contents. Add some ASCII art and you'll look like a super cool dude.

Now enjoy your Pi!


I had to look up various guides to do this.

What comes next

Raspian is the most common os to run on the raspberry pi. I want to experiment with some other Linux distros in the future, particularly Kali Linux because I plan on doing a lot of network projects in the future and Kali comes with a lot of network software preinstalled.