Setup a headless, (wireless) Raspberry Pi with Ubuntu Server 20.04.2 LTS (RPI 3/4/400)

Why the parenthesis around wireless? Because there is an issue with the cloudinit/netplan, I can’t figure out yet. The setup for wifi only works when an ethernet-cable is connected to the Raspi on first boot. After the initial first boot it works without ethernet. Strange!

The procedure is tested with Raspberry Pi 4 B.

  1. Start the Raspberry Pi Imager.
  2. Make a SD-Card with Ubuntu Server 20.04.2 LTS (RPI 3/4/400).
  3. Open the file “network-config” on the SD-Card with notepad++.
  4. This is a yaml configuration file. Yaml is a picky diva. There MUST be no tab-stop in the file. The indentations must all be spaces. Therefore you better switch on the visibility of the non printable characters.
  5. Make your changes. An example is below.
  6. Insert SD-Card in your Raspi.
  7. Connect the ethernet cable.
  8. Boot your Raspi.
  9. After a couple of minutes you will see your Raspi on your wired network. The wifi is not working yet.
  10. Rebooting the Raspi is activating the wifi connection. You can get rid of the ethernet cable now.
  11. Ssh is running. You can login over Wifi with PuTTY . The default login for Ubuntu server is
    User: ubuntu
    PW: ubuntu

Example network-config file

# This file contains a netplan-compatible configuration which cloud-init
# will apply on first-boot. Please refer to the cloud-init documentation and
# the netplan reference for full details:
#
# https://cloudinit.readthedocs.io/
# https://netplan.io/reference
#
# Some additional examples are commented out below

version: 2
ethernets:
  eth0:
    dhcp4: true
    optional: true
wifis:
  wlan0:
#    dhcp4: true
    addresses:
      - 192.168.0.66/24
    gateway4: 192.168.0.1
    nameservers:
      addresses: [192.168.0.1]
    optional: false
    access-points:
      "mywifi_net1":
        password: "mysecretpassword"
#      myworkwifi:
#        password: "correct battery horse staple"
#      workssid:
#        auth:
#          key-management: eap
#          method: peap
#          identity: "me@example.com"
#          password: "passw0rd"
#          ca-certificate: /etc/my_ca.pem
##Reboot after cloud-init completes
#power_state:
#  mode: reboot

Setup a headless, wireless Raspberry Pi

This procedure serves my convenience. No keyboard and mouse tampering. Simple.

Works with any Wifi-enabled Raspberry Pi.

Steps I took for Raspi Zero W and Pi 4 B:

  1. Make a bootable SD-Card with Raspberry PI Imager. For Example “Rasperry Pi OS Lite (32-Bit)”.
  2. Edit the SD-Card.
  3. In the root folder of “boot” create an empty file. Name it “ssh”. This will activate the OpenSSH-Service on next boot.
  4. Prepare Wifi connection by creating the file “wpa_supplicant.conf” in the same folder.
  5. Open the file and insert following text:
country=DE 
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev 
update_config=1 
network={
     ssid="WLAN SSID"
     scan_ssid=1
     psk="WLAN PASSWORT"
     key_mgmt=WPA-PSK
}
  1. You have to change “WLAN SSID” and “WLAN PASSWORT” to your needs, of course.
  2. Insert the edited SD-Card into Raspi and boot it.
  3. After booting the Raspi should be visible in your network as “raspberrypi.NETWORKNAME”. This is easy with the help of a network scanner.
  4. Now you can open a ssh connection with PuTTY. Confirm the ssh certificate.
  5. The default login is “pi” with password “raspberry”.
  6. I recommend changing the password with the “passwd” command.
  7. Install other missing software.
  8. Done.

Postscript:

2021-08-23 This does not work with Ubuntu Server 20.04.2 LTS (RPI 3/4/400)

2021-08-30 Instead of the above procedure, in the Raspberry Pi Imager you can type the magic key combination Ctrl-Shift-x for the advanced options.

Source of this information: