Configure Wi-Fi on Ubuntu Server for Raspberry Pi Using Netplan
Setting up headless Wi-Fi on a Raspberry Pi (Pi 3, Pi 4, or Pi 5) running Ubuntu Server LTS relies on Netplan (/etc/netplan/50-cloud-init.yaml), which generates backend configurations for systemd-networkd and wpa_supplicant.
Because YAML is whitespace-sensitive and modern versions of Netplan enforce strict file permissions when plain-text Wi-Fi passwords are present, a single tab character or overly permissive file mode can prevent wlan0 from associating at boot.
Update System Packages and Verify wpasupplicant
Before disconnecting the Ethernet cable, update the system packages and ensure wpasupplicant and wireless-tools are installed:
sudo apt update && sudo apt full-upgrade -y
sudo apt install -y wpasupplicant wireless-tools
Verify the wireless interface name (typically wlan0 on Raspberry Pi boards):
ip -br link show
Back Up and Edit /etc/netplan/50-cloud-init.yaml
Create a backup of the default cloud-init Netplan file and lock down its permissions to 0600 (required by Netplan on Ubuntu 22.04+ and 24.04+ to avoid Permissions for /etc/netplan/50-cloud-init.yaml are too open warnings):
cd /etc/netplan/
sudo cp 50-cloud-init.yaml 50-cloud-init.yaml.bak
sudo chmod 600 50-cloud-init.yaml
sudo nano 50-cloud-init.yaml
Add the wifis block under network:, using spaces only (never tabs) for indentation. Setting optional: true is critical so systemd-networkd-wait-online.service does not hang the boot sequence for 2 minutes if the Wi-Fi access point is temporarily unreachable:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
optional: true
wifis:
wlan0:
optional: true
dhcp4: true
access-points:
"your-ssid-here":
password: "your-wifi-password-here"
Validate and Apply the Netplan Configuration
Always validate syntax and renderer output with --debug generate and netplan try (which automatically rolls back after 120 seconds if you lose SSH connectivity):
sudo netplan --debug generate
sudo netplan --debug try
Once confirmed, apply the configuration permanently and verify that wlan0 obtains an IPv4 lease:
sudo netplan --debug apply
ip -4 addr show dev wlan0
Reboot the Raspberry Pi (sudo reboot) to confirm wlan0 connects automatically on cold boot.