How to enable headless networking on Ubuntu Mate on Raspberry Pi

I gave a talk tonight on Swift and how it works on the server-side as well as Raspberry Pi. I gave another talk about Swift on Raspberry Pi earlier in the year and I tried to use it like a full desktop. I had a keyboard, mouse and the projector hooked up to HDMI. That worked well, but it was clunky.

Nowadays, I consider a Raspberry Pi more like a tiny server. I ssh into it to execute commands and mount its filesystem with sftp. I can still work with its GPIO pins with a cobbler and a breadboard, but I don’t have an extra keyboard, mouse or monitor cluttering my desk.

However, the distribution that I’m using, Ubuntu Mate 16.04 for Raspberry Pi, does not start the WiFi until after you log in. Which requires a keyboard, mouse and monitor. I had these on a cart during my presentation tonight, but again it was clunky enough that it motivated me to figure out how to run it headless. I needed to ensure that the WiFi started when the system itself started, not waiting until a user logs in. I had done this in the past but forgot, so I am posting it here now.

The key is to declare your WiFi interface by appending the following to:

/etc/network/interfaces

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Then declare your WiFi network in the wpa_supplicant.conf referenced above (this is likely a new file):

/etc/wpa_supplicant/wpa_supplicant.conf

network={
    ssid="your-network-ssid-name"
    psk="your-network-password"
}

(Note, you can supply multiple network blocks as illustrated in Raspberry Pi Stack Exchange:
How to setup multiple WiFi networks?
)

Then reboot and you should be able to access your Pi after it starts up again!

Bonus tip: Ubuntu Mate seems to advertise itself via Bonjour. So if your pi is named “mario”, then you can ssh to it via “mario.local”.

Thanks to these references: How to setup your Raspberry Pi 2/3 with Ubuntu 16.04, without cables (headlessly) and WifiDocs/WPAHowTo