Skip to content

Instantly share code, notes, and snippets.

@MaiLinhGroup
Created February 4, 2019 22:21
Show Gist options
  • Save MaiLinhGroup/5c82e14b14fc708d4f6e5039b79cfc45 to your computer and use it in GitHub Desktop.
Save MaiLinhGroup/5c82e14b14fc708d4f6e5039b79cfc45 to your computer and use it in GitHub Desktop.
Enable ssh and bootstrap WiFi for Raspberry Pi 3 on OSX. Make it executable with "chmod +x enable_ssh_wifi_osx.sh".
#!/usr/bin/env bash
ssh_wifi() {
touch /Volumes/boot/ssh
touch wpa_supplicant.conf
echo "country=DE" >> wpa_supplicant.conf
echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev" >> wpa_supplicant.conf
echo "update_config=1" >> wpa_supplicant.conf
echo "network={" >> wpa_supplicant.conf
echo " ssid=\"$ssid\"" >> wpa_supplicant.conf
echo " psk=\"$psk\"" >> wpa_supplicant.conf
echo "}" >> wpa_supplicant.conf
mv wpa_supplicant.conf /Volumes/boot/wpa_supplicant.conf
# eject sd card after setup ssh and wifi
diskutil list
read -p "Enter disk identifier to eject the sd card: " disk
if [ -n $disk ]; then
sudo diskutil eject /dev/$disk
else
echo "Could not eject sd card, so diy."
fi
}
if [ -d "/Volumes/boot" ]; then
read -p "Enter SSID: " ssid
read -p "Enter PSK: " psk
ssh_wifi "$ssid" "$psk"
else
echo "Please insert the SD card and run the script again."
fi
Copy link

ghost commented Jul 29, 2022

helpful!
here is what I've added to mine..

....
.....
    echo "update_config=1"           >> wpa_supplicant.conf
+   echo "ap_scan=1"                 >> wpa_supplicant.conf   
    echo "network={"                 >> wpa_supplicant.conf
+   echo "        scan_ssid=1"       >> wpa_supplicant.conf
    echo "        ssid=\"$ssid\""    >> wpa_supplicant.conf
    echo "        psk=\"$psk\""      >> wpa_supplicant.conf
+   echo "        key_mgmt=WPA2-PSK" >> wpa_supplicant.conf
    echo "}"                         >> wpa_supplicant.conf
.....
....
...
..
.

adds support for hidden SSID,
useful in-case you use your pi as a IP-camera-hub (with ffmpeg or something),
and WPA2-PSK, to match what is the default in many routers now days (default is WPA-PSK).

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