Configuring your Raspberry Pi for headless operation
It is not always convenient to have an additional display keyboard and maybe a mouse occupying desk space. If you are like me, most I do is via a terminal session anyway. If needed I can start the X (graphical) environment and use VNC to have my desktop displayed in a window on my Mac (or Windows for that matter).
There are basically 2 important modifications you need to make where the first is a necessity and the second a must/nice to have.
- The first modification will enable the SSH server to be activated right after installation so it is accessible over the network.
- The second modification enables the connectivity to your WiFi when not using a cabled network.
For this example I have downloaded the latest version of the Raspbian image from the Raspberry Pi OS website. Once downloaded, double click the downloaded zip to extract. Then double click to mount the image.
MacOS will not recognize the Linux file system. For this article that is ok. We need the partition called boot anyway.
To have the system recognize that it needs to enable the ssh-server, we need to create an empty file called ssh on the boot partition. Open a terminal and do the following:
1
touch /Volumes/boot/ssh
That’s it. Now the empty file ssh is created and the Raspberry Pi will know to enable the ssh-server to be ready waiting for your connection.
For the Raspberry Pi to know what WiFi network to connect to, we need to create a file called wpa_supplicant.conf
and put information in it. In the terminal do the following:
1
2
touch /Volumes/boot/wpa_supplicant.conf
nano /Volumes/boot/wpa_supplicant.conf
Add the following to the wpa_supplicant.conf file with modifications to match your WiFi configuration:
1
2
3
4
5
6
7
8
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid=NETWORK-NAME
psk=NETWORK-PASSWORD
}
How to connect to the Personal Hotspot on your iPone, see this article.
Now with the two modifications it is time to unmount the image and write it to the SD card. How to do this, see my article writing and making backups of SD cards.
Once written the image to the SD card, put it in the Raspberry Pi and boot it. SSH will be automatically enabled and the Pi will connect to your WiFi.