Johnny Matthews | Connect to a Raspberry Pi Zero over USB on Ubuntu

I was messing around with a new Raspberry Pi Zero I got for Christmas, and I was surprised how convoluted it is to SSH into the device through the USB port. So I jotted down the steps and put them here. This was written on 6th of February 2021.

  1. Format micro SD card the normal way.

  2. Put an operating system on there using the Raspberry Pi Imager for Ubuntu.

  3. Change directory into the boot partition of the micro SD card:

    cd /media/johnny/boot
    
  4. Create a blank ssh file:

    touch ssh
    
  5. Add dtoverlay=dwc2 to the end of config.txt:

    echo "dtoverlay=dwc2" >> config.txt
    
  6. Add modules-load=dwc2,g_ether directly after rootwait within cmdline.txt:

    sed -i 's/rootwait/rootwait modules-load=dwc2,g_ether /g' input.txt
    
  7. Plug a micro-usb cable into the port closest to the HDMI port on the Raspberry Pi Zero. Plug the other end of the cable into your computer.

  8. Wait two minutes for the Raspberry Pi Zero to finish doing it’s thing.

  9. Open the Network panel in Settings and click the gear icon to open the settings for the Wired connection:

  10. Go to the IPv6 tab and set the IPv6 Method to Disable.

  11. Go to the IPv4 tab and set the IPv4 Method to Link-Local Only.

  12. Click Apply.

  13. Toggle the Wired connection off and then on again.

  14. Ping the Raspberry Pi Zero:

    ping raspberrypi.local
    
    > PING raspberrypi.local (169.254.194.96) 56(84) bytes of data.
    > 64 bytes from raspberrypi.local (169.254.194.96): icmp_seq=1 ttl=64 time=0.952 ms
    > 64 bytes from raspberrypi.local (169.254.194.96): icmp_seq=2 ttl=64 time=0.536 ms
    
  15. If you got a response to the ping, you should be able to connect to your Raspberry Pi Zero over USB. If you didn’t get a response, you might need to reboot your computer.

  16. If, after rebooting, you still can’t connect to your Raspberry Pi Zero, try using a different micro USB cable. Some cables are designed to only transfer power and not data.