Raspberry Pi - Updating WiFi settings

Having recently had my broadband router updated I found myself in the position where all the Pis which need to access WiFi required updating to enable them to access the new network.

Although it lives close by, on my desk, the PiZero stack runs headless and to update the settings I wanted something quicker than booting each one to a screen and editing the wpa_supplicant.conf locally.

Fortunately, I'm running Raspbian on all my nodes and my wpa_supplicant.conf files are simple, single-network configs. The WiFi settings on a nearby Pi 3 had been updated earlier in the week, this meant that the Pi 3 could be used to update each of the PiZero SD cards with a simple one-liner via a card reader connected to the Pi 3:

mkdir -p /tmp/usb && sudo mount /dev/sda2 /tmp/usb && sudo cp /tmp/usb/etc/wpa_supplicant/wpa_supplicant.conf /tmp/usb/etc/wpa_supplicant/wpa_supplicant.conf.$(date +%Y%m%d%H%M%S) && sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /tmp/usb/etc/wpa_supplicant/wpa_supplicant.conf && sudo umount /tmp/usb

This copies the Pi 3 wpa_supplicant.conf onto the SD card extracted from the PiZero, replacing the previous wpa_supplicant.conf.  This may not be desirable in situations where either the receiving machine, or the donor machine have a variety of networks configured, which are specific to the respective machines.

Should we need to extract some of the earlier settings, or even go back to the previous version, then a date-stamped version of the previous wpa_supplicant.conf is created prior to copying the newer file over.

Show Comments