We’ve written previously about how to configure WiFi and SSH on your Raspberry Pi without having to connect any peripheral devices (headless). As long as you’re comfortable on the command line, this makes it much easier to work with your Pi.
Now, I’ve been doing projects with Raspberry Pi’s since the first version, and I only recently found out about a Linux feature that allows you to connect to the Pi directly over USB: it’s called USB gadget mode. With “gadget mode” enabled, we don’t need to configure the WiFi network or connect any peripheral devices, we simply connect the Pi to our computer with a USB cable, and now we’ve got SSH access.
In this guide, I’ll show you how enable gadget mode and connect to your Pi via USB.
Note: I believe this feature was initially enabled for the Pi Zero, and it does not work on earlier versions of the Pi. I have, however, tested with the Raspberry Pi 4, and it works as long as you connect via the USB-C connector.