Raspberry Pi USB SSH Setup

Connect your Raspberry Pi via USB without network or monitor

Raspberry Pi USB SSH Without Network

Make sure to use a proper USB cable (data + power). You should see usb0 in ip a on your laptop when connected. If not, try a different cable. Tested on Raspberry Pi 400, Raspberry Pi 4, and Raspberry Pi Zero 2 W.
🎨 Command Color Coding:
🔧 Red commands = Execute on Raspberry Pi
💻 Blue commands = Execute on Host Machine

After flashing the image, edit:

cmdline.txt

Inside it, after rootwait, add:

modules-load=dwc2,g_ether

Note: Keep everything else at the beginning and end of the line. Just add that in between.

config.txt

Add this at the end of the file:

[all]
dtoverlay=dwc2

Log into the Raspberry Pi and create the following file:

Create /etc/systemd/network/usb0.network

🔧 Execute on Raspberry Pi:
sudo nano /etc/systemd/network/usb0.network

Note: use a different IP if you want to use multiple Raspberry Pis at the same time. Otherwise, leave it like this:

[Match]
Name=usb0

[Network]
Address=172.16.7.2/24

Enable systemd-networkd (if not already enabled)

🔧 Execute on Raspberry Pi:
sudo systemctl enable systemd-networkd
sudo systemctl restart systemd-networkd

Check

🔧 Execute on Raspberry Pi:
ip addr show usb0

Assign interface and IP on your host machine

💻 Execute on Host Machine:
sudo ip addr add 172.16.7.1/24 dev usb0
ping -c1 172.16.7.2

Troubleshooting: If usb0 interface is not found on host

If you don't see the usb0 interface when running ip a on your host machine, run this command to monitor kernel messages and look for USB device detection:

💻 Execute on Host Machine:
sudo dmesg -w

Connect the Raspberry Pi via USB and watch for messages about USB device detection. You should see messages related to the USB Ethernet gadget.

If the Raspberry Pi's interface is DOWN

💻 Execute on Host Machine:
sudo ip link set usb0 up

If it has no IP (assign different IP to avoid conflict):

💻 Execute on Host Machine:
sudo ip addr add 172.16.7.3/24 dev usb0

Now we can connect over USB and SSH.

If it doesn't respond, assign again:

💻 Execute on Host Machine:
sudo ip addr add 172.16.7.1/24 dev usb0
sudo ip link set usb0 up

After each reboot, use:

💻 Execute on Host Machine:
sudo ip addr add 172.16.7.1/24 dev usb0

Sometimes after SSH the IP gets unassigned. Just assign it again and it will work.

To avoid this, do the following:

This happens because NetworkManager in Kali controls usb0 and removes the manual IP. To prevent it:

✅ Option 1: Disable NetworkManager control over usb0

  1. Create a config file to ignore usb0:
  2. 💻 Execute on Host Machine:
    sudo mkdir -p /etc/NetworkManager/conf.d
    sudo nano /etc/NetworkManager/conf.d/10-ignore-usb0.conf
  3. Paste this inside:
  4. [keyfile]
    unmanaged-devices=interface-name:usb0
  5. Restart NetworkManager:
  6. 💻 Execute on Host Machine:
    sudo systemctl restart NetworkManager
  7. Assign the IP and it won't be removed anymore:
  8. 💻 Execute on Host Machine:
    sudo ip addr add 172.16.7.1/24 dev usb0