Repository for Ideas & Research
Open Source GIS, Hydrologic Modeling, Optimization

How to enable the SSH service before booting the Raspberry Pi Zero W for the first time

In this How-To, my goal is to enable the SSH service even before booting the Pi in a headless mode.

First, you need to install Raspbian to a microSD card.

unzip -p | dd of=/dev/mmcblk0 bs=4M conv=fsync status=progress

Once you installed Raspbian, mount the microSD card and set up WiFi.

# your device may be different, but you want to mount the second partition (p2)
mount /dev/mmcblk0p2 /mnt

# create wpa_supplicant.conf
cat > /mnt/etc/wpa_supplicant/wpa_supplicant.conf <<EOT
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


# unmount
umount /mnt

Now, you can enable the SSH service.

# this time, you need to mount the first partition (p1)
mount /dev/mmcblk0p1 /mnt

# create a new file called ssh
touch /mnt/ssh

# unmount
umount /mnt

Everything is ready. Boot the Pi for the fist time. It should connect to your WiFi and you should be able to connect to the Pi using an SSH client.

# your Pi IP address may be different
# the default user is pi
ssh pi@

# the default password is raspberry
Password: raspberry