Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save calebbrewer/837732c5f4f12d12c1226bfcf55a3219 to your computer and use it in GitHub Desktop.
Save calebbrewer/837732c5f4f12d12c1226bfcf55a3219 to your computer and use it in GitHub Desktop.

#Headless Setup of Raspberry Pi Zero W (Raspberry Pi 3 Wireless) (macOS)

  1. Formatt the Micro SD card - Open a terminal and type 'diskutil list'. Find your card and copy the disk name (For example: /dev/disk4). Format the card with diskutil eraseDisk ExFat temp disk4(Use your disk here)
  2. Download Raspbian - wget https://downloads.raspberrypi.org/raspbian_lite_latest
  3. Unmount the SD card - diskutil unmountDisk /dev/disk4 or whatever your disk path is
  4. Mount the Raspbian image to the card - sudo dd if=PATH-TO-RASPBIAN-IMAGE of=/dev/disk4` or whatever your disk path is
  5. Enable SSH on the Pi - cd /volumes && ls. You should see a boot partition from the SD card cd boot && touch ssh
  6. Setup WiFi on the PI - While still in the boot partition of the card type nano wpa_supplicant.conf and enter network={ ssid="YOUR-SSID" psk="YOUR-WIFI-PASSWORD" }
  7. Boot the PI - Unmount the card diskutil unmountDisk /dev/disk4 (or whatever your disk path is) and put it in the Pi, then power up the Pi
  8. SSH Into the Pi - Find the Pi's IP on your network by running arp -a or using an app like LanScan and ssh into it ssh pi@YOUR_PIS-IP. THe default password is raspberry
  9. Add your SSH key to the PI - While in the Pi run install -d -m 700 ~/.ssh. On you machine run cat ~/.ssh/id_rsa.pub | ssh <USERNAME>@<IP-ADDRESS> 'cat >> .ssh/authorized_keys'

YouTube video of this setup: https://www.youtube.com/watch?v=Ct9XwyYvmbU

@asheshambasta
Copy link

asheshambasta commented Sep 10, 2017

Thanks for the guide, but there are several issues with this, at least in my case.

  • wget wget https://www.raspberrypi.org/downloads/raspbian/ doesn't download the raspbian image, I don't know if something changed with redirects on the download page.
  • after dd and cd /Volumes/boot, I only see
-> % ls
.

I can create new files in this directory but not see them. Rough ride with the Pi so far for me, I guess 😞

@asheshambasta
Copy link

So, since I failed to ssh into the pi, I had to power it off by unplugging. Since then, it looks like it has bricked by SD card. I cannot write to it anymore.

@calebbrewer
Copy link
Author

Sorry to hear that...
Can you reformat the SD card on your Mac and then run dd to flash the OS image again?

If after dd finishes you don't see a dir named "boot" in the "/Volumes" dir then pull the sd card out and put it back in. You may also not see it if you had another volume that was named "boot" and it was not ejected before you removed it. Just look in finder and see if there is a drive showing up after dd is done.

I am fixing the download link. It should be" https://downloads.raspberrypi.org/raspbian_lite_latest

I hope you get it working!

@antenorr
Copy link

Hi Caleb,
I have a Raspberry pi 3 - and followed the directions several times - however it seems that once i place the sd card into the pi - there is no network connection AND once i put card back into MAC the ssh file and the config file are no longer there! BUT if i do the set up as instructed > take out the card and immediately put it back it back in the MAC the two files are there with no problem -- but it seems as if they are deleted once placed in the raspberry -- any thoughts?

@ckalegi
Copy link

ckalegi commented Nov 29, 2017

@antenorr - Raspbian checks the contents of the boot directory for a few specific files at startup:

  • If it detects wpa_supplicant.conf, Raspbian moves the file into /etc/wpa_supplicant, overwriting any existing wpa_supplicant.conf file in there.
  • If an empty file named ssh is detected, Raspbian adjusts it's settings to accept SSH connections, and deletes the file.

@ckalegi
Copy link

ckalegi commented Nov 29, 2017

Also, if you're using 'Stretch' you need to include the full wpa text in your wpa_supplicant.conf file:

wpa_supplicant.conf

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

network={
	ssid="your-network-service-set-identifier"
	psk="your-network-WPA/WPA2-security-passphrase"
	key_mgmt=WPA-PSK
}

@GeoffreyPlitt
Copy link

Got this working on Mac with an SDXC 64GB card. Worked on OS X 10.13.4.

The first few steps should be slightly different:

@a-gavin
Copy link

a-gavin commented Sep 4, 2018

I think it is important to note that by saving your wpa_supplicant.conf with "YOUR-WIFI-PASSWORD" in step 6, your pi will store your wifi password in plain text. If security isn't a major concern, then ignore this, but in case you'd like to change this, I suggest you read the "Connecting with wpa_passphrase" section of this wiki article:

https://wiki.archlinux.org/index.php/WPA_supplicant

@CommanderPoe
Copy link

Hey Caleb i was wondering how can i assigned an Static IP Address to the PI once i set this one over the WIFI correctly?

@ConnorNusser
Copy link

How do you do this on a public network?

@babarrett
Copy link

Hope this helps someone else...

I tried this and it wasn't working. I eventually figured out that my issue was that my WiFi router supports both:

  • Wireless Network (2.4GHz b/g/n), and
  • Wireless Network (5GHz a/n/ac)

Using a 5GHz a/n/ac network failed, but using the 2.4GHz b/g/n worked!
Make sure you're NOT using a 5GHz network for your ssid network name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment