Skip to content

Instantly share code, notes, and snippets.

@etoxin
Last active March 28, 2024 11:16
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etoxin/d96418f0732c0de36f0f3c22f9bdd75d to your computer and use it in GitHub Desktop.
Save etoxin/d96418f0732c0de36f0f3c22f9bdd75d to your computer and use it in GitHub Desktop.
SSH over USB on a Raspberry Pi

Our long term goal will be to use SSH over USB. This means that we have to configure Raspbian to treat the USB port like an ethernet port. Mount the micro SD card in a computer (not Pi Zero) and open it with Finder, or Windows Explorer, or whatever it is that you use.

The first thing that you want to do is open a file at the root of the mounted drive called config.txt. In this file you want to add the following line at the very bottom:

dtoverlay=dwc2

The above line will set us up for the next file that we alter. The next file we alter is cmdline.txt, but it is a bit different. Parameters in this file are not delimited by new lines or commas, they are delimited by space characters. In this file we want to add the following:

modules-load=dwc2,g_ether

The above parameter should be added after the rootwait parameter. Yes the above parameter is a single parameter, meaning don’t add a bunch of space characters to it. More information on networking over USB on Linux can be found here.

By default SSH access is disabled in Raspbian. To enable SSH, create a file called ssh and save it to the root directory of the boot mount on the SD card. The file can be blank, and it has no extensions. It should exist at the same location as the other files that were edited.

At this point the micro SD can be inserted into the Pi Zero.

Connecting to the Pi Zero with USB and SSH

Connect to the pi's Data port. No need to use the pwr port. (The middle port is data [PWR, DATA, HDMI])

Connect to ssh pi@raspberrypi.local

@mrsfixit
Copy link

@etoxin thanks for this guide - it worked when I plugged my Pi Zero into the USB port on my mac (that is on my wireless network).

However instead of plugging my Pi Zero into the USB port on my mac, I'd like to plug it in to a Pi Zero W (that is also on my wireless network).
ie. effectively piggy packing the Pi Zero on to the Pi Zero W (using a micro-usb to micro-usb OTG cable).

I'm assuming I have to make some kind of configuration for usb0 in /etc/network/interfaces on the Pi Zero W (and I don't imagine I have to configure anything on the Pi Zero as my mac is connecting without that), but I've been struggling to find a guide on exactly how to do it amongst all the other guides.
All I seem to be able to find is "Connecting to the Pi Zero with USB and SSH" ... but only from a PC/mac - not from a Pi Zero W.

Do you know where I could find one?

@BjoernRave
Copy link

@mrsfixit did you have any success with that? I am looking to do the same, specifically I want to connect a rpi zero 1.3 to a rpi 4b over usb and send data from the zero over udp to the rpi 4

@TheRaf974
Copy link

Hi,

I had an issue connecting the raspberry to my computer. It appeared as a com serial port because of missing driver. I had to download, install and link RNDIS driver to the "Serial port" in order to get windows see it as ethernet.

If anyone else as this issue, here is the solution.

Ps: I have Windows 11

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