Skip to content

Instantly share code, notes, and snippets.

@superdodd
Created September 1, 2016 05:15
Show Gist options
  • Save superdodd/06b91ba03899e47beb43078b27dc601e to your computer and use it in GitHub Desktop.
Save superdodd/06b91ba03899e47beb43078b27dc601e to your computer and use it in GitHub Desktop.
Set up a Raspberry Pi Zero (with only a USB cable) via OS X
  1. Download the Raspbian Lite image from https://downloads.raspberrypi.org/raspbian_lite_latest (add .torrent to get a torrent)
  2. Unzip the download to extract the .img file
  3. Insert a FAT32-formatted SD card, and copy the image over:
    • diskutil list to identify the disk number, e.g. /dev/disk2
    • diskutil unmountDisk /dev/disk2
    • sudo dd bs=1m if=image.img of=/dev/rdisk2
  4. Before unmounting, edit a couple of files to activate internet-over-USB. The image mounted for me at /Volumes/boot.
    • In config.txt, add this as the last line of the file: dtoverlay=dwc2
    • In cmdline.txt, add this as a parameter, just after the rootwait parameter: modules-load=dwc2,g_ether
  5. Unmount the SD card (via Finder) and stick it in the Raspberry Pi.
  6. Attach a USB cable from your Mac to the RPi via the "USB" port on the RPi. This should power the RPi, and it will start to boot up.
  7. Give it a few minutes to boot. Open the Network preference panel (System Preferences -> Network) on your Mac, and you should see a new networking device called something like "RNDIS/Ethernet Gadget". For now it should be set to "Configure via DHCP" - it will have a link-local address.
  8. Once the RPi boots, you should be able to SSH to it with ssh [email protected]. The password is raspberry.
  9. Over SSH, edit /etc/network/interfaces to add a USB interface - add the following lines:
  allow-hotplug usb0
  iface usb0 inet static
      address 192.168.2.2
      netmask 255.255.255.0
      gateway 192.168.2.1
  1. Next, set up resolv.conf to use 192.168.2.1 for name resolution - edit /etc/resolvconf.conf, and uncomment/edit the nameservers line to read nameservers=192.168.2.1.
  2. Finally, on your Mac, configure the RNDIS/Ethernet Gadget interface with the following parameters: - Configure IPV4: Manually - IP Address: 192.168.2.1 - Subnet Mask: 255.255.255.0 - Router: (none) - Under Advanced -> DNS, add your favorite DNS server, like 8.8.8.8 or your home router.
  3. Under the "Sharing" preferences pane, turn on Internet Sharing, and share your Mac's active network connection with the RNDIS/Ethernet Gadget interface.
  4. Reboot the RPi. After it comes back up, you should still be able to connect via ssh [email protected], and the device should now have the IP address 192.168.2.2 and access to the Internet!
@rricharz
Copy link

Works nicely, except under step 4, create an empty file called ssh in the boot directory, because ssh is disabled in the newest Jessie image for safety reasons. This enables ssh.

@fronbasal
Copy link

It's easier to just set up "sharing options" -> "internet sharing", it will auto-update the DNS and use the .local resolver, for example raspberrypi.local will then resolve to 192.168.2.2 in my case.

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