Site.eu

How to get Let's Encrypt SSL with Certbot or acme.sh

5 min read

How to get Let's Encrypt SSL with Certbot or acme.sh

Do you run your own server? A VPS, a Docker host, Proxmox or a NAS at home? Then you can get free Let's Encrypt certificates for it. For every domain name that uses our DNS. Even wildcards, like *.example.com.

How does it work? Let's Encrypt wants proof that the domain name is yours. So it asks for a TXT record called _acme-challenge. Certbot or acme.sh adds that record through our API. Let's Encrypt checks it. Then the record is removed again. Renewals work the same way, all by themselves.

Do you use our web hosting or website builder? Then you don't need this. Your website gets SSL there already: read SSL with web hosting or SSL with the website builder.

What you need

  • A domain name in your Site.eu account. A domain name registered elsewhere that you added to your account works too.
  • Our DNS management is on for that domain name. That's the default for domain names you register with us. For a domain name registered elsewhere, read how to make it work with our services.
  • Root access to your server, or sudo.

Make an API key

Certbot and acme.sh need an API key to add the record. Make a key that can do this one thing only.

Step 1: Log in to your dashboard and go to Settings, on the API keys tab. Click Add API key.

Step 2: Give the key a name, such as "Let's Encrypt". Open API Endpoints and tick only Add and remove Let's Encrypt check records (_acme-challenge TXT only).

Step 3: Leave MCP Tools empty. Click Create API Key at the bottom.

Step 4: Copy the key right away and keep it somewhere safe. You only see it once.

Why only that one tick? Your key sits on a server. If someone ever steals it, they can't do much with it. This key can only add and remove _acme-challenge TXT records. It can't read or change your other DNS records. And it can't touch anything else in your account. It can still get certificates for your domain names, though. So keep it safe, and delete it when you no longer use it.

A key with Modify domain DNS records also works. But that key can change all your DNS records, so we advise against it. More about API keys: how to get started with the API.

Certbot

Our Certbot plugin is called certbot-dns-site-eu. Don't mind the name: it works on all our sites. Install it in the same Python environment as Certbot:

python3 -m venv /opt/certbot
/opt/certbot/bin/pip install certbot certbot-dns-site-eu
ln -s /opt/certbot/bin/certbot /usr/local/bin/certbot

Do you have Certbot from Snap? That version can't use our plugin yet. Install it with pip as above.

Now save your API key in a file, for example /root/.secrets/site-eu.ini, with this one line:

dns_site_eu_api_key = your-API-key

Make sure only root can read it:

chmod 600 /root/.secrets/site-eu.ini

Then get your certificate. This example covers example.com and all its subdomains:

certbot certonly --authenticator dns-site-eu --dns-site-eu-credentials /root/.secrets/site-eu.ini -d example.com -d '*.example.com' --deploy-hook "systemctl reload nginx"

The last part reloads your web server after every new certificate, so it uses the new one right away. Using Apache? Then write apache2 instead of nginx.

Certbot waits 90 seconds before Let's Encrypt checks the record. Does the check fail? Add --dns-site-eu-propagation-seconds 120 to wait longer. Never go below 90. A new record can take up to a minute to reach all our nameservers.

Certbot remembers these settings. So certbot renew renews your certificate without them. With a pip install, you plan that renewal yourself. For example with a daily line in crontab -e:

0 3 * * * /opt/certbot/bin/certbot renew -q

The code and more options are on GitHub.

acme.sh

Our acme.sh script is called dns_site_eu and works on all our sites too. It isn't part of acme.sh yet. Until it is, download it once:

curl -o ~/.acme.sh/dnsapi/dns_site_eu.sh https://raw.githubusercontent.com/internetco/acme.sh/dns_site_eu/dnsapi/dns_site_eu.sh

Then give it your API key and get your certificate:

export SITE_EU_API_KEY="your-API-key"
acme.sh --issue --server letsencrypt --dns dns_site_eu -d example.com -d '*.example.com'

Why --server letsencrypt? Without it, acme.sh asks ZeroSSL for the certificate instead of Let's Encrypt. Want Let's Encrypt for all your certificates? Then set it once with acme.sh --set-default-ca --server letsencrypt.

acme.sh saves your key for renewals. It also renews by itself: it set up its own cron job when you installed it. Use --install-cert to copy the certificate to where your web server needs it.

Other tools

Do you use another ACME client, or your own code? You only need two API calls, each with your key in the header X-API-Key:

POST https://backend.site.eu/v2/dns/acme_challenge
POST https://backend.site.eu/v2/dns/acme_challenge/remove

Send a JSON body with two fields. name is the record, such as _acme-challenge.example.com. value is the check value from Let's Encrypt. The first call adds the record, the second removes it again.

You don't send the domain name separately. We read it from the record name. A subdomain works too, such as _acme-challenge.shop.example.com. All details are in our API documentation.

Something wrong?

  • AUTH_006 or HTTP 401: the key is wrong, or it doesn't have the Let's Encrypt permission. Check it on the API keys tab, or make a new key.
  • DOMAIN_NOT_FOUND: the domain name isn't in the account of this key.
  • DNS_002: the domain name doesn't use our DNS. Turn our DNS management on first.
  • Let's Encrypt can't find the record: wait longer. With Certbot, set the propagation seconds to 120.
  • A try failed? Wait 2 minutes before you try again. With acme.sh, you can also add --dnssleep 120.
  • A CNAME on _acme-challenge: did you point _acme-challenge somewhere else, for example to acme-dns? Then remove that CNAME record first.

Still stuck? Contact us by WhatsApp, Telegram or email.

Couldn’t find what you were looking for?

You can always chat with one of our experts for any questions you might have!

New articles added