Raspberry Pi USB SSH Without Network
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.
🔧 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
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)
sudo systemctl enable systemd-networkd
sudo systemctl restart systemd-networkd
Check
ip addr show usb0
Assign interface and IP on your 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:
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
sudo ip link set usb0 up
If it has no IP (assign different IP to avoid conflict):
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:
sudo ip addr add 172.16.7.1/24 dev usb0
sudo ip link set usb0 up
After each reboot, use:
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
- Create a config file to ignore
usb0: - Paste this inside:
- Restart NetworkManager:
- Assign the IP and it won't be removed anymore:
sudo mkdir -p /etc/NetworkManager/conf.d
sudo nano /etc/NetworkManager/conf.d/10-ignore-usb0.conf
[keyfile]
unmanaged-devices=interface-name:usb0
sudo systemctl restart NetworkManager
sudo ip addr add 172.16.7.1/24 dev usb0