Skip to content

Instantly share code, notes, and snippets.

@Shourai
Last active October 15, 2017 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shourai/a5cdb27be30f0b1ecd9f2ccb14a95edb to your computer and use it in GitHub Desktop.
Save Shourai/a5cdb27be30f0b1ecd9f2ccb14a95edb to your computer and use it in GitHub Desktop.
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:

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="SSID"
    psk="Password"
}

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=192.168.0.100 /24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1 8.8.8.8

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