Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Raspberry Pi headless installation

SSH over USB

To edit files on a raspberry pi when you are unable to mount ext4 disks, it is possible to enable SSH over USB. This is also useful if you do not have any peripherals you can attach to the pi. If however you are running linux you can directly edit /etc/wpa_supplicant/wpa_supplicant.conf, etc/network/interfaces and /etc/dhcpcd.conf.

Enable SSH

There was a security update to the Raspian images. To enable ssh you need to put a blank ssh file in the boot directory.

touch /Volumes/boot/ssh

This will write an empty file to the root of your Raspian image. That will enable ssh on startup

Edit config.txt

In the root folder of the SD card, open config.txt (/Volumes/boot/config.txt) in a text editor Append this line to the bottom of it: dtoverlay=dwc2 Save the file

Edit cmdline.txt

In the root folder of the SD card, open cmdline.txt in a text editor/ After rootwait, append this text leaving only one space between rootwait and the new text (otherwise it might not be parsed correctly): modules-load=dwc2,g_ether If there was any text after the new text make sure that there is only one space between that text and the new text Save the file

SSH to raspberry pi

ssh pi@raspberrypi.local

Setup Wi-Fi

edit /etc/wpa_supplicant/wpa_supplicant.conf and add:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


It is also possible to put a wpa_supplicant.conf file in the boot directory like ssh containing the info above.

Setup wlan interfaces

edit etc/network/interfaces and add:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Setup static ip-address

edit /etc/dhcpcd.conf and add:

interface wlan0
static ip_address= /24
static routers=
static domain_name_servers=

edit the ip-address to match your own.
interface = This defines which network interface you are setting the configuration for.
static ip_address = This is the IP address that you want to set your device to. (Make sure you leave the /24 at the end).
static routers = This is the IP address of your gateway (probably the IP address or your router) . static domain_name_servers = This is the IP address of your DNS (probably the IP address of your router).
You can add multiple IP addresses here separated with a single space.

Disable SSH over USB

Remove dtoverlay=dwc2 and modules-load=dwc2,g_ether from config.txt and cmdline.txt respectively. You need to do this step to allow SSH over wlan.

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