Raspberry Pi automatic wifi and ssh

I'm writing this down so I don't have to google it every time.

This is how to enable ssh and wifi before booting into your raspberry pi for the first time.

Make sure your SD card partitions are mounted

SSH

Pretty simple:

touch /media/$USER/boot/ssh

Wifi

printf "country=US\n\
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\n\
update_config=1\n\
\n\
network={\n\
    ssid=\"%s\"\n\
    psk=\"%s\"\n\
}\n" 'your-wifi-network-name' 'your-wifi-password' > /media/$USER/boot/wpa_supplicant.conf

Hostname

Having a bunch of rpis on the same network with the same hostname is pretty obnoxious, so I adjust them with the following:

echo 'new-hostname' | sudo tee /media/$USER/rootfs/etc/hostname

I like to pick something cool from my monitor name generator.