How to automate ssl certificate generation with certbot

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g., so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is: "" "" ""

I ran this command:

DEPLOYMENT_BUCKET=~/certbot_bucket  ## here's my workspace
DOMAINS=("" "" "")  ## domain my ssl cert creates for 
PROJECTS=("example-demo") ## my projects

## 90 days letsencrypt cert will expiry
# now i get the expiry date and delete folde with name of expiry date and create new folder with expiry date, where my ssl cert can be placed at. 
EXPIRATION_DATE=$(date -v +90d "+%Y-%m-%d")

## now i'm looping through domains, to create ssl cert one by one
for domain in "${DOMAINS[@]}"
 # now i use certbot creating my ssl cert. I want to automate the creation process and i just need to get the ssl cert. I will upload ssl certs to google cloud later
 echo certbot certonly --manual --work-dir=$CERT_DIR --logs-dir=$CERT_DIR --config-dir=$CERT_DIR --agree-tos --email "" --manual-auth-hook $DEPLOYMENT_BUCKET/certbot/ --manual-cleanup-hook $DEPLOYMENT_BUCKET/certbot/ -d *.$domain --noninteractive

 certbot certonly --manual --work-dir=$CERT_DIR --logs-dir=$CERT_DIR --config-dir=$CERT_DIR  --agree-tos --email ""  --manual-auth-hook $DEPLOYMENT_BUCKET/certbot/ --manual-cleanup-hook $DEPLOYMENT_BUCKET/certbot/ -d *.$domain --noninteractive
 for project in "${PROJECTS[@]}"

  # DO project stuff here. Here i upload ssl certs to google cloud projects. 

It produced this output:

Saving debug log to ~/certbot/2021-03-08/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Account registered.
Requesting a certificate for *
Performing the following challenges:
dns-01 challenge for
Running manual-auth-hook command: ~/certbot/
Output from manual-auth-hook command

Error output from manual-auth-hook command
expr: syntax error
Traceback (most recent call last):
  File "<string>", line 1, in <module>
IndexError: list index out of range
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'NoneType' object has no attribute '__getitem__'

Waiting for verification...
Challenge failed for domain
dns-01 challenge for
Cleaning up challenges
Running manual-cleanup-hook command: ~/certbot/
Some challenges have failed.

 - The following errors were reported by the server:

   Type:   dns
   Detail: DNS problem: NXDOMAIN looking up TXT for - check that a DNS record exists
   for this domain

My web server is (include version):
i just use certbot to generate ca recognized ssl certificate. It's not attached to web server yet. I only plan to create the ssl certificate locally. My local computer is MacOS. I think currently it has nothing to do with my web server.

The operating system my web server runs on is (include version): it doesn't matter

My hosting provider, if applicable, is: No

I can login to a root shell on my machine (yes or no, or I don't know): I just ran it locally to get ssl certs

I'm using a control panel to manage my site (no, or provide the name and version of the control panel): No

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot): i tried with certbot 1.10.1 and certbot 1.8.0. Both gave me same error.

What's with the whole bucket script thingy? Where does that come from? What's the exact reason for usage?

to help you understand i update the question and script. @Osiris
You can see more explanation behind "##" in above script.

What i'm trying to do is automate the ssl cert creation process and i only need to generate the ssl certs. I will upload the ssl certs to google cloud later

I can read and understand the script, I just don't understand the why if the script. It looks like it does functions which certbot itself can do perfectly?

In any case, it looks like your authenticator script is malfunctioning.

I'm new to the tool cerbot. Maybe there's some advanced functions certbot processes and i'm not familiar with.
You said some malfunctioning in "authenticator script".
Here is my authenticator script.
I need to use cloudflare dns for verification. And the scripts are copied from


# Get your API key from
API_KEY="xxx" # TODO Pleas update to your cloudflare api key 
EMAIL="xxx" # TODO Pleas update to your cloudflare email

# Strip only the top domain to get the zone id
DOMAIN=$(expr match "$CERTBOT_DOMAIN" '.*\.\(.*\..*\)')

# Get the Cloudflare zone id
     -H     "X-Auth-Email: $EMAIL" \
     -H     "X-Auth-Key: $API_KEY" \
     -H     "Content-Type: application/json" | python -c "import sys,json;print(json.load(sys.stdin)['result'][0]['id'])")

# Create TXT record
RECORD_ID=$(curl -s -X POST "$ZONE_ID/dns_records" \
     -H     "X-Auth-Email: $EMAIL" \
     -H     "X-Auth-Key: $API_KEY" \
     -H     "Content-Type: application/json" \
     --data '{"type":"TXT","name":"'"$CREATE_DOMAIN"'","content":"'"$CERTBOT_VALIDATION"'","ttl":120}' \
             | python -c "import sys,json;print(json.load(sys.stdin)['result']['id'])")

# Save info for cleanup
if [ ! -d /tmp/CERTBOT_$CERTBOT_DOMAIN ];then
        mkdir -m 0700 /tmp/CERTBOT_$CERTBOT_DOMAIN

# Sleep to make sure the change has time to propagate over to DNS
sleep 25


# Get your API key from
API_KEY="xxx" # TODO Pleas update to your cloudflare api key
EMAIL="xxx" # TODO Pleas update to your cloudflare email

if [ -f /tmp/CERTBOT_$CERTBOT_DOMAIN/ZONE_ID ]; then


# Remove the challenge TXT record from the zone
if [ -n "${ZONE_ID}" ]; then
    if [ -n "${RECORD_ID}" ]; then
        curl -s -X DELETE "$ZONE_ID/dns_records/$RECORD_ID" \
                -H "X-Auth-Email: $EMAIL" \
                -H "X-Auth-Key: $API_KEY" \
                -H "Content-Type: application/json"

@Osiris error always complains "check that a DNS record exists for this domain". In authenticator script, i already provided with cloudflare api token and email, why it can't add TXT record itself and do verification ? My goal is to fully automate the ssl cert creation.

  • Don't use those example, scripts, it is clearly stated in the documentation:

Example usage for DNS-01 (Cloudflare API v4) (for example purposes only, do not use as-is)

  • Use the certbot-dns-cloudflare plugin to use the dns-01 challenge if you require it (wildcard certificate, no access on port 80 on your server or certbot is not running on the server)
  • Use the http-01 challenge if you don't require a wildcard certificate, port 80 is functioning and certbot is running on the server (which isn't the case in your situation I understand)

All the things from your script can be added to the standard certbot functionality. Certbot is by default setup that it will renew when there are 30 or less days left until expiry and the "project stuff" can be put in a script which can run as a --deploy-hook. See the certbot documentation for more info about that hook.


Thanks it works @Osiris

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.