Introduction #
I see a lot of people struggling with setting up
https://in their homelab - for some cases, you cant avoid it (for example Vaultwarden). With this guide you can automatically create and renew SSL Certificates for your homelab webserver with the help of Lets Encryt and certbot.
Requirements #
- a domain you own
- an account at Hetzner or IONOS
- terminal access to your server
DNS and API Token #
Below you find the instructions for Hetzner or IONOS. Select your preferred provider.
This guide got updated to the new “Hetzner Console”, “Hetzner DNS” will be discontinued by Hetzner (https://dns.hetzner.com).Hetzner
IONOS
Certbot: Set up SSL Certificate #
Install certbot #
- connect to the terminal of your server (ssh).
- install the snap paket manager:
sudo apt install snapd - install certbot with snap:
sudo snap install --classic certbot - add certbot to PATH:
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Below you find the instructions for Hetzner or IONOS. Select your preferred provider.
Source: Github - certbot-dns-ionosHetzner
Configure certbot for Hetzner
#
sudo snap install certbot-dns-hetzner-cloudsudo snap set certbot trust-plugin-with-root=ok
sudo snap connect certbot:plugin certbot-dns-hetzner-cloud
certbot plugins* dns-hetzner-cloud in the plugin list./etc/hetzner.ini:
nano /etc/hetzner.ini
dns_hetzner_cloud_api_token = addyourtokenhere
chmod 0600 /etc/hetzner.ini
Request a new certificate
#
sudo certbot certonly --agree-tos --authenticator dns-hetzner-cloud --dns-hetzner-cloud-credentials /etc/hetzner.ini -d <example.com>
/etc/letsencrypt/live/example.com/fullchain.pem and ../privkey.pem, which you can now use!IONOS
Configure certbot for IONOS
#
sudo snap install certbot-dns-ionossudo snap set certbot trust-plugin-with-root=ok
sudo snap connect certbot:plugin certbot-dns-ionos
certbot plugins* dns-ionos in the plugin list./etc/ionos.ini:
nano /etc/ionos.ini
dns_ionos_prefix=YOUR_PREFIX
dns_ionos_secret=YOUR_SECRET
dns_ionos_endpoint=https://api.hosting.ionos.com
chmod 0600 /etc/ionos.ini
Request a new certificate
#
certbot certonly \
--agree-tos \
--authenticator dns-ionos \
--dns-ionos-credentials /etc/ionos.ini \
--dns-ionos-propagation-seconds 60 \
--agree-tos \
--rsa-key-size 4096 \
-d <example.com>
/etc/letsencrypt/live/example.com/fullchain.pem and ../privkey.pem, which you can now use!
Automate the renewal #
To automate the renewal of the certificate, just add the renewal command to your crontab.
- Open your crontab :
crontab -e - Add the renewal command at the end of the file:
# Certbot Lets Encrypt renewal 0 3 * * 6 root /usr/bin/certbot renew >> /var/log/certbot-renew.log 2>&1 - This will run the renewal every saturday at 3 am, also the ouput gets logged in /var/log/certbot-renew.log.
- Hint: if you use Apache2 or NGINX for example, dont forget to restart the service after the renewal (in the crontab). I just added this some minutes after the renewal runs:
10 3 * * 6 root systemctl restart nginx
Nice to know #
Some helpful knowledge about certbot, that could help you:
- you can enter multiple subdomains with -d in the certbot command, for example:
-d <example.com> -d <sub1.example.com> -d <sub2.example.com> - you can also request wildcard certificates with
*:-d <*.example.com>
Fix issues #
If you get an error with certbot when requesting the SSL Cert:
- is your API Token correctly entered and safed?
- can your server reach the API service of Hetzner / IONOS?
- Hetzner: https://dns.hetzner.com/api/v1
- IONOS: https://api.hosting.ionos.com/dns
- For Hetzner: did you successfully add your domain to the DNS console before and set the Hetzner nameservers at your domainhoster? You can test that by manually adding an entry in the DNS Console of Hetzner and use an online DNS lookup tool to check, if the record was successfully registered.