Installing UniFi Controller Software on a Raspberry Pi

Even though I've deployed thousands of dollars worth of Ubiquiti equipment for clients, I don't actually have any in my home.  Today, that changes with the delivery of the Switch Flex Mini (USW-Flex-Mini). Since this is a fairly barebones product, it does not come with Bluetooth® for provisioning. Fortunately, I have a plethora of Raspberry Pis available for installing the UniFi software on.

Before you purchase a USW-Flex-Mini, be aware that you can only use a single untagged VLAN per switch port. You cannot setup ports to use custom port profiles (e.g. multiple tagged VLANs per port).

Initialize the Pi

I'm using a Pi 3 with a 64GB SD card, connected to the network via Ethernet.

sudo apt update && sudo apt upgrade -y && reboot
First, update the packages and reboot the Pi.
$ passwd
Changing password for pi.
Current password:
New password:
Retype new password:
passwd: password updated successfully
If you haven't already, change the default password.

Enable Randomness

In order for the UniFi software to start without hanging, rng-tools must be installed to make use of the Pi's built-in random number generator.

sudo apt install rng-tools
Install rng-tools.
sudo nano /etc/default/rng-tools
Edit the rng-toolsconfig file.

Uncomment the following line:

HRNGDEVICE=/dev/hwrng
This line enables the integrated random number generator (based on thermal noise).
sudo systemctl restart rng-tools
Restart rng-tools for the change to take effect.

Install OpenJDK

sudo apt install openjdk-8-jre-headless
This installs the OpenJDK flavour of the Java Runtime Environment (JRE), version 8.

Install the UniFi Controller Software

In order to install the UniFi software, the repository and its GPG keys must be added.

echo 'deb https://www.ui.com/downloads/unifi/debian stable ubiquiti' | sudo tee /etc/apt/sources.list.d/ubnt-unifi.list
sudo wget -O /etc/apt/trusted.gpg.d/unifi-repo.gpg https://dl.ui.com/unifi/unifi-repo.gpg
sudo apt update
Add the UniFi repository to the debian sources list, and install the UniFi GPG key that will be used to verify the authenticity of the downloaded packages.

Just like we installed rng-tools and the JRE, the UniFi Controller software can be installed with this simple command:

sudo apt install unifi

Once that command if finished, you should be able to access the console at https://raspberrypi:8443 (replace raspberrypi with the IP address of your Pi). You will get a certificate warning as well, which you should normally not bypass, however this is okay since the Pi is within your local network. To avoid the certificate warnings, you could set up your own private PKI (like cloudflare/cfssl: CFSSL: Cloudflare's PKI and TLS toolkit) or use Lets Encrypt.