Setting up a Raspberry Pi 4 in a headless configuration with Ubuntu Server can be an efficient and powerfull way to deploy a compact server at home with a very little human interaction. This guide will walk you through the process, from flashing the SD card to configuring it for automatic Wi-Fi connection at first boot, without any manual intervention with the keyboard or the screen.
Flash the SD card with Raspberry Pi Imager
To begin, you’ll need to flash Ubuntu Server 22.04 LTS onto an SD card using the Raspberry Pi Imager. You can download the Raspberry Pi Imager from the Raspberry Pi website. Once you’ve downloaded and installed the Raspberry Pi Imager, open it and select the Choose OS option. From the list of operating systems, select Ubuntu and then Ubuntu Server 22.04 LTS.
Note: When the Imager ask you if you want to edit system settings before writing the image, select NO since we want to use the default settings which we will change later, when the SD card is flashed.
Click next and wait for the image to be flashed onto the SD card. Once the image has been flashed, you can close the Raspberry Pi Imager.
Modify Configuration Files for Wi-Fi Access
Now that the SD card has been flashed, we need to modify some configuration files to allow the Raspberry Pi to connect to Wi-Fi automatically at first boot. Note that RPi Imager has automatically unmount the SD card after flashing, so you’ll need to remove it and reinsert it into your computer. Once you’ve done that, open the SD card in your file explorer and navigate to the
system-boot folder. In this folder, you’ll find a file called
network-config. Open this file in a text editor and setup your Wi-Fi network configuration. Here is an example of a network configuration file:
hidden: false # Set to true if your Wi-Fi network is hidden
Make sure to replace the
WIFI_NETWORK_PASSWORD_GOES_HERE with your Wi-Fi network name and password. If your Wi-Fi network is hidden, uncomment the
hidden: true line. Once you’ve done that, save the file and close it.
At the first boot, the Raspberry Pi will use netplan to configure the network interfaces. Netplan will read the
network-config file and configure the Wi-Fi network interface accordingly. I’ve noticed that sometimes, the Raspberry Pi will not connect to the Wi-Fi network at first boot so we need to add configuration to the
user-data that will ensure that the Raspberry Pi reboot after the network configuration has been applied. To do that, open the
user-data file (also located in the
system-boot folder) in a text editor and add the following lines at the end of the file:
Once you’ve done that, save the file and close it.
First Boot and SSH Connection
Now that the SD card has been flashed and the configuration files have been modified, you can eject the SD card from your computer, insert it into the Raspberry Pi and power it on. The Raspberry Pi will boot and connect to your Wi-Fi network. The router will assign an IP address to the Raspberry Pi. To find the IP address, you can use the router’s web interface or you can use a network scanner. Once you’ve found the IP address, you can connect to the Raspberry Pi using SSH.
Note: You’ll be prompted to change the password at first login.
IP_ADDRESS with the IP address of the Raspberry Pi assigned by your router. Once you’ve connected to the Raspberry Pi, you can configure it to your liking.
That’s it! You now have a headless Raspberry Pi running Ubuntu Server 22.04 LTS. This guide is based on my own experience and I hope it will help you to setup your own headless Raspberry Pi. If you have any questions or comments, feel free to leave them below in the comments section. I will try to answer them as soon as possible. Thank you for reading!