Headless setup for a Raspberry Pi
A headless Raspberry Pi is one that does not need a monitor, keyboard or mouse. It can be used remotely over the network, by connecting to it using SSH or VNC.
There are many instructions on the Web about how to configure the Wi-Fi and enable the SSH server, by creating a wpa_supplicant.conf and ssh file in the boot partition of the microSD card. The Raspberry Pi Imager v1.6, released in March 2021, also has a hidden advanced mode for this and to perform some additional configurations. But both have limitations, such as they do not set up the VNC server.
I’ve written a shell script to set up a microSD card for headless operation.
It can configure the following:
- Wi-Fi settings;
- SSH server;
- default “pi” user account password;
- default “pi” user account adding a SSH public key to .ssh/authorized_keys file;
- VNC server; and
- force the Raspberry Pi to assume there is a HDMI display with a particular resolution.
With it, setting up a headless Raspberry Pi is easy:
- Image the Raspberry Pi OS onto a microSD card.
- Run the script.
- Put the microSD card in the Raspberry Pi and turn it on.
Download it from the raspi-headless-setup GitHub repository.