Unifi Dream Router Certbot Automation
Scripted SSL Certificates on the UDR?
I had a HECK of a time attempting to find a clear and concise method to install signed certs onto my UDR for use with the Admin Web Interface and Hotspot Landing Page. I ended up piecing together a method that works and writing a script to automate this process. At the time of writing, this has only been tested on a Unifi Dream Router running UniFi OS 3.2.12
DISCLAIMER
The Following assumes you
- Have Extensive knowledge of DNS and its inner workings as pertains the FQDNs involved
- Have decent knowledge of LetsEncrypt
- Have a working knowledge of the Debian OS and how to create a bash script
- Have SSH access to your UDR
Be sure to replace <Your FQDN> and <Your EMAIL> in the code snipped below.
#!/bin/bash
# Ensure certbot is installed
if ! command -v certbot &>/dev/null; then
echo "Certbot is not installed. Installing..."
sudo apt-get update
sudo apt-get install certbot -y
fi
# Stop the Unifi service
sudo systemctl stop unifi
# Obtain the certificate
sudo certbot certonly --manual --preferred-challenges dns -d <Your FQDN> --agree-tos --email <Your EMAIL>
# Replace The Certs
cp /etc/letsencrypt/live/<Your FQDN>/fullchain.pem /data/unifi-core/config/unifi-core.crt
cp /etc/letsencrypt/live/<Your FQDN>/privkey.pem /data/unifi-core/config/unifi-core.key
# Restart the Unifi service
sudo systemctl start unifi
Run this code from the root users home folder
I created this bash script within the root users home folder. I installed nano to create the script because I DETEST vim. After creating the script, I made it executable using chmod +x