How can I SSH to a headless Raspberry PI Zero (no GPIO pins, no WiFi) over a USB cable, connecting to a Mac using a shell window from Mac's Terminal program?


6 Answers 6


I found this very helpful for setting up mine: https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/ethernet-gadget

The essential steps are:

1: open up the boot partition on the micro sd with finder and in the file config.txt add dtoverlay=dwc2 to a line on the bottom and save it.

2: Create a new file called ssh using textedit and save it onto the boot partition. Use 'get info' to remove the extension on the file, and it should appear as an EXEC file. You can now eject the card and boot it on your RPi

3: Finally, open up the cmdline.txt. replace all text with this:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether quiet init=/usr/lib/raspi-config/init_resize.sh 

Be careful with this step as the formatting is very picky in this file

4: Eject your MicroSD card and boot it up in your pi! make sure you plug the usb cable from your mac into the USB input of your pi - this can also power it.

5: Once its booted you should now be able to open up terminal, and using ping raspberrypi.local you can see the RPi's IP address.

6: Using this address in terminal tpye ssh pi@<Pi's IP Address>

7: It should ask you for a password, this will default be


I'd also recommend having a look at 'VNC Viewer' - a piece of free software that lets you run your pi as a virtual machine inside your mac, all you need is the IP address which you will get when doing the ssh connection


Hope this helps!

  • The deadline IO scheduler was replaced with mq-deadline and does not exist in recent Linux kernels in Bullseye.
    – jiggunjer
    Nov 22, 2021 at 2:53

After you've done what @Barnaby Hewitt says then this issue may occur:

In my case the Ubuntu host machine could not connect to the Pi Zero via SSH because the Ubuntu machine failed to retrieve an IP address. In order to fix that I set static IP addresses on both ends.

I mounted the SD card to the Ubuntu host machine and I created a file on the mounted SD card, ^path_to_mounted_sd^/rootfs/etc/network/interfaces.d/usb0 containing:

allow-hotplug usb0
iface usb0 inet static

After saving the file and successfully un-mounting the SD card I put it in the Pi and plugged connected my Pi to my computer via a USB cable.

Ubuntu's network manager started to show this icon: enter image description here indicating that it tries to retrieve an IP using DHCP. In the end it will fail so we will need to provide a static IP address.

Next you will need to locate the static IP address of the Ubuntu host machine. List all interfaces in order to locate the one that does not yet have an IP address via the ifconfig command. Afterwards run:

sudo ifconfig enp0s20f0u6 netmask

In my case enp0s20f0u6 is the interface that was located using the ifconfig command on the Ubuntu host. Then I could manage to connect using the command:

ssh [email protected]

Because I did not change the default password yet I used raspberry to connect to the Pi.

In case you plug the Pi to the very same USB then you may want to have these network settings remain the same. For the configuration use the Ubuntu's /etc/network/interfaces or use the network manager in order to set these settings.


In my case Ubuntu 19.04 I didn't get IP address from Raspberrypi Zero

You can fix it easy just change "USB Ethernet" settings

**IPv4 Method** 
 Automatic (DHCP) --> Link-Local Only

After that you will get a 169.254.xxx.xxx IP address.

ping raspberrypi.local
ssh [email protected]

enter image description here

  • 1
    An address in that range is a public IP. That's somewhat suspicious, especially if you're claiming that to be a general answer.
    – Brick
    Jun 19, 2019 at 19:26
  • 1
    @Brick is almost always an IP address assigned automatically by an interface that's set to get its IP via DHCP but can't get one - not a public ip.
    – SnapShot
    Dec 9, 2019 at 22:13
  • Thanks, that worked flawlessly for me on linux mint.
    – steffres
    Jan 2, 2022 at 22:58

For me it did not work; This works (with IP only if I also edit the file /etc/network/interfaces with

allow-hotplug usb0
iface usb0 inet static

That I got from another place ( https://gist.github.com/gbaman/975e2db164b3ca2b51ae11e45e8fd40a ); may be ok instead of

Hope this can be useful for others reading this question.


I'll add my 3 cents - maybe it will save someone a few hours.

My setup was still failing with ssh: Could not resolve hostname raspberrypi.local even though I've done all needed steps: (config.txt, cdmline.txt, ssh file) and "Link-Local Only" network setting. I could have connected to RPi by IP address, but I could only discover it by running mmap or arp-scan that both took forever. It turns out that for some reason this Bonjur-like auto-config didn't work when connected through my usb-hub. After connecting directly to my PC it worked like charm.


In case anyone else stumbles up on this in future I ran into issues with the Pi4 I had the Pi Zero plugged into. Namely that USB0 came up with a 169.x.x.x link only address. Took me a minute to figure out what was wrong and here are some snippets.

$ ifconfig usb0
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast

No worries so I changed the USB0 address to the Note my Zero config was set to

$ sudo ifconfig usb0 netmask

Still no connectivity but TCP dump shows packets from (Pi Zero).

$ sudo tcpdump -i usb0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on usb0, link-type EN10MB (Ethernet), capture size 262144 bytes
16:56:56.584779 ARP, Request who-has dns.google tell raspberrypi.local, length 28
16:56:57.428907 IP6 fe80::768e:30aa:7659:e902.mdns > ff02::fb.mdns: 0 PTR (QM)? (45)
16:56:57.429024 IP > 0 PTR (QM)? (45)
16:56:57.430578 IP > 0*- [0q] 1/0/0 (Cache flush) PTR raspberrypi.local. (70)

The route table did not setup the 192 network but did have the 169 network.

$ route -n
...     U     207    0        0 usb0

Lets fix that

$ sudo route del -net gw netmask dev usb0
$ sudo ip route add dev usb0
$ ping
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=1.10 ms
64 bytes from icmp_seq=2 ttl=64 time=0.444 ms

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.