Quickly Enable WiFi and SSH on a Headless Raspbian Installation
For those of us who don’t have any extra ethernet cables or external keyboards laying around.
Clone Raspbian to an SD card
- Download the ISO from raspberrypi.org
- Mount the SD card to your computer and find the location using
diskutil list
. You’ll get an output similar to below.
$ diskutil list
/dev/disk0 (internal):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme 251.0 GB disk0
1: EFI EFI 314.6 MB disk0s1
2: Apple_APFS Container disk1 250.7 GB disk0s2
/dev/disk1 (synthesized):
#: TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme - +250.7 GB disk1
Physical Store disk0s2
1: APFS Volume Macintosh HD 77.1 GB disk1s1
2: APFS Volume Preboot 123.1 MB disk1s2
3: APFS Volume Recovery 2.6 GB disk1s3
4: APFS Volume VM 1.1 GB disk1s4
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *64.0 GB disk2
1: Windows_FAT_32 43.8 MB disk2s1
2: Linux 1.8 GB disk2s2
In my case, the SD card is located at /dev/disk2
.
Flash the ISO
You’ll need to unmount the disk before flashing.
$ diskutil umountDisk /dev/disk2
$ sudo dd if=path/to/raspbian.img of=/dev/disk2 bs=4m
Mount the SD card
$ sudo diskutil mountDisk /dev/disk2
When mounted, the path on macOS is usually /Volumes/boot
.
Enable WiFi
To enable WiFi, create a file named wpa_supplicant.conf
in the root directory with the following content:
`
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="YOUR_SSID"
scan_ssid=1
psk="YOUR_PASS"
key_mgmt=WPA-PSK
}
Replace YOUR_SSID
with the name of your SSID and YOUR_PASS
with the password.
Enable SSH
To enable ssh, you just have to create an empty file named ssh
in the root directory:
$ cd /Volumes/boot
$ touch ssh
All done!
Now boot up your Raspberry Pi with the SD card and you’ll be able to ssh in as the pi
user.