Skip to content
masdzub.com
~/articles/tls — one from the notebook

Automating TLS certificate renewal with Certbot and systemd timers

A practical guide to automating Let's Encrypt certificate renewal with Certbot, systemd timers, hooks, and reliable troubleshooting on Linux.

masdzub@website:~$ cat ~/articles/automating-tls-certificate-renewal-with-certbot-and-systemd-timers.aspx.md
# 1 file · 21 min read · topic: tls · status: published

Introduction

Automating TLS certificate renewal with Certbot and systemd timers means installing Certbot, obtaining a certificate through an ACME challenge, and running certbot renew periodically through a systemd service triggered by a systemd timer. The timer checks for expiring certificates, while the renewal service performs the work only when a certificate is close to expiry.

A reliable setup also handles HTTP-01 or DNS-01 challenges, reloads the service that uses the certificate, captures renewal logs, and tests the failure path. This guide covers that setup on Debian, Ubuntu, RHEL-family systems, and other Linux distributions that use systemd.

The exact commands vary slightly between distributions because package names and web-server integration differ. The underlying model stays the same: Certbot manages certificates and renewal state, systemd schedules the check, and the web server or load balancer reloads the renewed certificate.

How Certificate Renewal Works

ACME issuers issue short-lived certificates, so certificate management has two separate jobs. The first job creates a certificate. The second job checks existing certificates and replaces any that will expire soon.

Certbot stores the private key, full-chain certificate, and renewal configuration under /etc/letsencrypt. A typical deployment includes these files:

/etc/letsencrypt/
├── accounts/
├── archive/
│ └── example.com/
│ ├── cert1.pem
│ ├── chain1.pem
│ ├── fullchain1.pem
│ └── privkey1.pem
├── live/
│ └── example.com/
│ ├── cert.pem -> ../../archive/example.com/cert1.pem
│ ├── chain.pem -> ../../archive/example.com/chain1.pem
│ ├── fullchain.pem -> ../../archive/example.com/fullchain1.pem
│ └── privkey.pem -> ../../archive/example.com/privkey1.pem
└── renewal/
└── example.com.conf

The files in /etc/letsencrypt/live are symbolic links. Applications should continue pointing at those paths rather than the numbered files in /etc/letsencrypt/archive. When Certbot renews a certificate, it updates the links to the new archive version.

A typical renewal configuration contains the certificate domain, account information, authenticator, and challenge type:

[renewal]
version = 3.0
archive_dir = /etc/letsencrypt/archive/example.com
cert = /etc/letsencrypt/live/example.com/cert.pem
privkey = /etc/letsencrypt/live/example.com/privkey.pem
chain = /etc/letsencrypt/live/example.com/chain.pem
fullchain = /etc/letsencrypt/live/example.com/fullchain.pem
[renewalparams]
authenticator = webroot
webroot_path = /var/www/html
server = https://acme-v02.api.letsencrypt.org/directory

The renewal timer can run more frequently than the certificate lifetime because certbot renew does not replace a healthy certificate. If a certificate has plenty of time left, Certbot exits without changing it.

Prerequisites and DNS Configuration

The machine running Certbot needs a stable public DNS record for every domain covered by the certificate. The ACME server must be able to reach the challenge endpoint. The firewall, cloud security group, reverse proxy, and application server must all permit the required traffic.

Before requesting a certificate, verify that each hostname resolves to the expected public address:

Terminal window
dig +short example.com A
dig +short www.example.com A
dig +short api.example.com A

IPv6 records need separate attention. If the DNS provider publishes an AAAA record, the ACME server may attempt validation over IPv6. If IPv6 routing is broken, validation can fail even when IPv4 works. Remove invalid AAAA records or repair the IPv6 configuration.

Choose an HTTP-01 or DNS-01 challenge based on how the certificate will be used:

  • HTTP-01 is simpler for websites served directly from the host or behind a reverse proxy. It requires port 80 to be publicly reachable for the challenge path.
  • DNS-01 works for internal services, wildcard certificates, and environments where inbound port 80 is unavailable. It requires a supported DNS provider plugin and API credentials.
  • TLS-ALPN-01 requires port 443 and is useful in some network appliances, but it is not the usual first choice for a web server deployment.

HTTP-01 requires this endpoint to return the token supplied by the ACME server:

http://example.com/.well-known/acme-challenge/<token>

The response body must contain the token, and redirects to another host should be avoided unless the redirect remains accessible to the public ACME server.

Installing Certbot

On Debian and Ubuntu, install Certbot and the appropriate plugin. The Nginx plugin can create the temporary challenge configuration. Apache, standalone, webroot, and DNS plugins use different installation packages.

Install the Nginx integration on Debian or Ubuntu:

Terminal window
sudo apt update
sudo apt install certbot python3-certbot-nginx

Install the Apache integration instead if Apache manages the site:

Terminal window
sudo apt update
sudo apt install certbot python3-certbot-apache

Install only Certbot when a separate webroot or DNS plugin is enough:

Terminal window
sudo apt update
sudo apt install certbot

On RHEL, Fedora, and AlmaLinux, the available packages depend on the repository versions. Search for the package names before installing:

Terminal window
sudo dnf search certbot

A common installation on RHEL-family systems uses the operating system packages:

Terminal window
sudo dnf install certbot python3-certbot-nginx

For the webroot plugin on a system where it is packaged separately:

Terminal window
sudo dnf install certbot python3-certbot-nginx

On Fedora, the package names may already be installed by a dependency chain. Confirm availability with:

Terminal window
dnf info certbot
dnf info python3-certbot-nginx

Some distributions package Certbot through Snap, Homebrew, Python’s package manager, or a third-party installation method. Avoid mixing package-manager and Snap installations on the same host. They can create separate configuration directories, commands, and renewal state.

Verify the installed version and location:

Terminal window
certbot --version
command -v certbot
certbot plugins

Record the output. The executable path and plugin list matter when diagnosing why renewal behaves differently from the initial certificate request.

Obtaining the First Certificate

Choose one workflow for the first issuance rather than mixing authenticators in the same certificate configuration. The webroot workflow is predictable when the web server already has a fixed document root and the server does not need to stop during validation.

Create a writable challenge directory:

Terminal window
sudo mkdir -p /var/www/html/.well-known/acme-challenge
sudo chown "$USER":"$USER" /var/www/html/.well-known/acme-challenge

Confirm that the web server exposes that directory at the public URL:

Terminal window
printf 'certbot-test\n' > /var/www/html/.well-known/acme-challenge/test
curl -fsS http://example.com/.well-known/acme-challenge/test

The curl command should print:

certbot-test

If it returns a 404, inspect the virtual host configuration, document root, directory permissions, and any redirect rules.

Request a certificate with the webroot authenticator:

Terminal window
sudo certbot certonly \
--webroot \
--webroot-path /var/www/html \
--cert-name example.com \
--domains example.com,www.example.com \
--email admin@example.com \
--agree-tos \
--non-interactive

The --cert-name option gives the certificate a stable name. Without it, Certbot derives a name from the first domain. A stable name matters when scripts or service units reference a specific path.

For Nginx-managed sites, the plugin can modify the virtual host during the initial request:

Terminal window
sudo certbot certonly --nginx \
--cert-name example.com \
--domains example.com,www.example.com \
--email admin@example.com \
--agree-tos \
--non-interactive

For an Apache-managed site:

Terminal window
sudo certbot certonly --apache \
--cert-name example.com \
--domains example.com,www.example.com \
--email admin@example.com \
--agree-tos \
--non-interactive

For a temporary standalone listener, stop the service that owns ports 80 and 443 before requesting the certificate:

Terminal window
sudo systemctl stop nginx
sudo certbot certonly --standalone \
--cert-name example.com \
--domains example.com,www.example.com \
--email admin@example.com \
--agree-tos \
--non-interactive
sudo systemctl start nginx

The standalone method is awkward for unattended renewal because the web server must stop on every renewal attempt. A deployment should use webroot, a server plugin, or DNS-01 instead.

Inspect the result:

Terminal window
sudo certbot certificates
sudo openssl x509 \
-in /etc/letsencrypt/live/example.com/fullchain.pem \
-noout \
-subject \
-issuer \
-dates

The certificate should list the intended domains and show a valid start and expiration date.

Testing Manual Renewal

Before installing a timer, test the renewal path with the staging environment. Staging certificates are not trusted by normal clients, but they exercise ACME account creation, challenge handling, renewal configuration, and deployment hooks without affecting the production certificate.

Use the staging endpoint explicitly:

Terminal window
sudo certbot renew \
--dry-run \
--staging \
--cert-name example.com

A successful run ends with output similar to:

Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/example.com/fullchain.pem (cert.pem)

The exact wording can vary by Certbot release. If the command reports that the certificate is not yet due for renewal, use --force-renewal during a controlled staging test:

Terminal window
sudo certbot renew \
--dry-run \
--staging \
--force-renewal \
--cert-name example.com

Run the staging test again after changing the web server configuration, firewall rules, DNS records, or deployment hook. A successful initial issuance does not guarantee that unattended renewal will work.

Creating a systemd Renewal Service

Systemd timers can invoke certbot renew directly, but a dedicated service gives the team control over environment variables, execution privileges, timeout behavior, and logging. The service should run as root because Certbot needs to update private keys and renewal state under /etc/letsencrypt.

Create /etc/systemd/system/certbot-renew.service:

[Unit]
Description=Renew Let's Encrypt certificates
Documentation=https://eff-certbot.readthedocs.io/
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --quiet

Check the Certbot path before using this unit:

Terminal window
command -v certbot

If the result is not /usr/bin/certbot, replace ExecStart with the actual path. Using an absolute path avoids PATH differences between an interactive shell and the service manager.

For automatic deployment, add a hook that reloads the service using the certificate. Create /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh:

#!/usr/bin/env bash
set -euo pipefail
/usr/bin/systemctl reload nginx

Make the script executable:

Terminal window
sudo chmod 0750 /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

The deploy hook runs only after a successful renewal. The pre-hook directory runs commands before renewal attempts, while the post-hook directory runs them after the attempt regardless of whether renewal occurred.

Test the script directly before relying on it:

Terminal window
sudo /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
sudo systemctl status nginx

For multiple applications, create separate scripts with explicit service names. A hook that reloads one service should not silently reload unrelated applications.

Creating a systemd Timer

Create /etc/systemd/system/certbot-renew.timer:

[Unit]
Description=Check Let's Encrypt certificate renewal twice daily
Documentation=https://eff-certbot.readthedocs.io/
[Timer]
OnCalendar=*-*-* 03,15:00:00
RandomizedDelaySec=3600
Persistent=true
[Install]
WantedBy=timers.target

This timer starts at 03:00 and 15:00, with a random delay of up to one hour. The delay avoids a synchronized burst on many hosts that use the same schedule.

Persistent=true causes systemd to run a missed timer task after the machine starts if the system was powered off during the scheduled window. It does not make Certbot renew a certificate that is too far from expiry. The certbot renew command still decides whether renewal is required.

Enable and start the timer:

Terminal window
sudo systemctl daemon-reload
sudo systemctl enable --now certbot-renew.timer

Check its state:

Terminal window
systemctl list-timers certbot-renew.timer
systemctl status certbot-renew.timer

A healthy timer should show the next expected run. If the timer shows no future trigger, run:

Terminal window
systemd-analyze calendar '*-*-* 03,15:00:00'

For a randomized delay, systemd-analyze cannot display the exact next run time because the final execution time is selected inside the delay window. The timer list still shows a scheduled window.

Use the timer without a random delay when a precise schedule matters more than load spreading:

[Timer]
OnCalendar=*-*-* 03,15:00:00
AccuracySec=1min
Persistent=true

Running the Timer Manually

Test the service directly before waiting for the timer:

Terminal window
sudo systemctl start certbot-renew.service
systemctl status certbot-renew.service

For scripts and CI checks, the command returns a nonzero status when the service fails:

Terminal window
sudo systemctl start certbot-renew.service

Inspect the journal:

Terminal window
journalctl -u certbot-renew.service \
--since today \
--no-pager

The unit’s --quiet option suppresses routine output, but errors remain available in the journal. Remove --quiet during initial troubleshooting so Certbot prints each renewal decision and hook result.

Check whether the timer itself has failed:

Terminal window
systemctl status certbot-renew.timer
journalctl -u certbot-renew.timer --since today --no-pager

A timer can be active while its associated service has failed. Check both units during an incident.

Reloading Services That Use the Certificate

A renewal can succeed while the running application continues serving the old certificate in memory. Nginx, Apache, HAProxy, and several other daemons read certificate data at startup or reload time.

For Nginx, create a deploy hook that validates the configuration before reloading it:

#!/usr/bin/env bash
set -euo pipefail
/usr/sbin/nginx -t
/usr/bin/systemctl reload nginx

Save it as /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh:

Terminal window
sudo chmod 0750 /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

For Apache, use:

#!/usr/bin/env bash
set -euo pipefail
/usr/sbin/apachectl configtest
/usr/bin/systemctl reload apache2

On RHEL-family systems, the Apache service is commonly named httpd:

#!/usr/bin/env bash
set -euo pipefail
/usr/sbin/httpd -t
/usr/bin/systemctl reload httpd

HAProxy can validate its configuration with:

#!/usr/bin/env bash
set -euo pipefail
/usr/sbin/haproxy -c -f /etc/haproxy/haproxy.cfg
/usr/bin/systemctl reload haproxy

A reload hook should fail when validation fails. The set -euo pipefail settings and command ordering accomplish that. Do not put || true after the validation command, because that would hide the exact problem the hook is intended to catch.

Some applications do not reload certificate files dynamically. In that case, restart the service after renewal:

#!/usr/bin/env bash
set -euo pipefail
/usr/bin/systemctl restart my-application

Restarting has a larger availability impact than reloading. Use it only when the application cannot load the new certificate without a restart.

Handling Multiple Certificates

A single certbot renew invocation checks all renewal configurations that Certbot knows about. This is useful for hosts with several domain names, but it also means one failing certificate can affect the overall command result.

List the certificates:

Terminal window
sudo certbot certificates

Inspect individual renewal configurations:

Terminal window
sudo cat /etc/letsencrypt/renewal/example.com.conf

A systemd timer can run the general renewal command:

Terminal window
ExecStart=/usr/bin/certbot renew --quiet

For a strict deployment where one service owns all certificates, keep that broad scope and improve the per-certificate hooks. For isolated environments, run one service and timer per certificate:

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --quiet --cert-name example.com

Then give each timer a distinct name:

certbot-example-com.service
certbot-example-com.timer

This arrangement isolates failures. It also creates more operational overhead, so it is usually unnecessary for a small server hosting several sites under the same administration.

DNS-01 and Wildcard Certificates

A wildcard certificate covers a domain and its immediate subdomains, such as example.com and *.example.com. Public Certificate Authority validation requires DNS-01 for wildcards because the ACME server cannot request a wildcard over HTTP.

Install the DNS plugin supplied by the operating system or by Certbot. For example, a plugin package might be named python3-certbot-dns-cloudflare or certbot-dns-cloudflare, depending on the source. Check available packages first:

Terminal window
apt-cache search certbot-dns | grep -i provider

For a Cloudflare-managed DNS zone, create a restricted API token with permission to edit DNS for the target zone. Store the credentials in a file that is not world-readable:

Terminal window
sudo install -d -m 0700 /etc/letsencrypt
sudo sh -c 'cat > /etc/letsencrypt/cloudflare.ini' <<'EOF'
dns_cloudflare_api_token = YOUR_RESTRICTED_API_TOKEN
EOF
sudo chmod 0600 /etc/letsencrypt/cloudflare.ini

Use a placeholder in production documentation and replace it through a secrets manager or provisioning process. Avoid putting the token directly into a shell history or a committed configuration file.

Request a wildcard certificate:

Terminal window
sudo certbot certonly \
--dns-cloudflare \
--dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini \
--cert-name example.com \
--domains example.com,*.example.com \
--email admin@example.com \
--agree-tos \
--non-interactive

The DNS provider plugin creates temporary TXT records during validation and removes them afterward. Some providers retain records longer or require cleanup of old challenge values. Review the plugin documentation for the selected provider.

DNS-01 is also appropriate when port 80 is closed or the service is not publicly reachable. Its downside is that credentials gain DNS modification rights. Restrict those rights to the narrowest zone and API actions that the plugin requires.

ACME Staging and Production Separation

The Let’s Encrypt staging environment issues untrusted certificates. It is the correct place to test account registration, DNS credentials, hooks, and validation behavior. Run at least one staging renewal before relying on production automation.

Terminal window
sudo certbot renew \
--dry-run \
--staging \
--force-renewal

Do not add --staging permanently to the systemd service if the goal is to renew production certificates. Instead, remove the argument after the staged test passes:

ExecStart=/usr/bin/certbot renew --quiet

If the account was created against staging, Certbot may create a separate production account during a later production renewal. Check the account list when behavior differs between manual and scheduled runs:

Terminal window
sudo certbot show_account

Logging and Monitoring

The systemd journal is the primary log source on hosts using systemd. A simple monitoring check can look for failed renewal services:

Terminal window
systemctl is-failed certbot-renew.service

For local alert delivery, install a small monitor that checks the timer and certificate expiration. A shell script can check the expiration timestamp with OpenSSL:

#!/usr/bin/env bash
set -euo pipefail
certificate=/etc/letsencrypt/live/example.com/fullchain.pem
expiration_date=$(date -d "$(openssl x509 -enddate -noout -in "$certificate" | cut -d= -f2)" +%s)
current_date=$(date +%s)
remaining_days=$(( (expiration_date - current_date) / 86400 ))
if (( remaining_days < 15 )); then
logger -t certbot-monitor "Certificate expires in ${remaining_days} days"
fi

This script only logs the problem. Connect it to the existing monitoring system, such as Prometheus node exporter textfile collectors, Nagios, Icinga, or an email and webhook delivery mechanism already used by the team.

A timer schedule alone does not guarantee renewal. Monitor the certificate expiration independently and alert when the remaining lifetime falls below a threshold. A useful threshold is shorter than the normal monitoring interval and the time needed to repair DNS, firewall, plugin credentials, or web-server configuration.

For multi-certificate hosts, iterate over /etc/letsencrypt/live/*/fullchain.pem and report the smallest remaining lifetime. Exclude symbolic links that do not point to a valid certificate.

Certificate Renewal Timing

Let’s Encrypt certificates are currently valid for 90 days, although the exact validity period can change under the CA’s policy. Certbot normally renews when a certificate is within its configured renewal window, commonly 30 days before expiration for certificates issued through the ACME protocol.

Do not schedule renewal only a few days before expiry. If a DNS API token expires, a firewall rule changes, or the server is unavailable, a narrow window leaves little time to recover. A timer that checks twice per day gives the operator repeated opportunities during the normal renewal period.

Use a dry run to inspect the current renewal threshold:

Terminal window
sudo certbot renew --dry-run --verbose

The dry run reports which certificates would be renewed. If the certificate is not near the renewal window, use --force-renewal for testing. Do not use --force-renewal routinely in the timer, because it would request a new certificate on every run even when no replacement is needed.

Troubleshooting ACME Validation Failures

A common renewal failure looks like this:

Failed to renew certificate example.com: urn:ietf:params:acme:error:connection
Failed authorization for example.com
urn:ietf:params:acme:error:connection: 400 :: urn:ietf:params:acme:error:connection :: dns :: NXDOMAIN looking up A for example.com

This usually means the ACME server could not reach the challenge endpoint or the DNS name did not resolve as expected. Check public DNS from outside the local network:

Terminal window
dig +short example.com A
curl -I http://example.com/.well-known/acme-challenge/test

A different error points to a missing challenge file:

Detail: The keyauthorization file from the server did not match this challenge

Compare the challenge response with the token and authorization stored by Certbot. Confirm that the web server is serving the same directory passed through --webroot-path. Also check for a reverse proxy or CDN that caches, rewrites, or blocks /.well-known/acme-challenge/.

Another common error is:

Some challenges have failed.
Failed authorization for example.com
urn:ietf:params:acme:error:unauthorized: 400 :: urn:ietf:params:acme:error:unauthorized :: Invalid response from http://example.com/.well-known/acme-challenge/token: 404

The ACME server received a 404 response. The webroot directory is not mounted correctly, the virtual host points to a different document root, or a redirect sends the request to another host.

For DNS-01, errors may identify a missing or incorrect TXT record:

DNS problem: NXDOMAIN looking up TXT of _acme-challenge.example.com

Recheck the record from public resolvers:

Terminal window
dig +short TXT _acme-challenge.example.com @1.1.1.1

Wait until the public DNS reflects the challenge record, then rerun the renewal. Some DNS providers propagate records slowly, and Certbot’s own authoritative check is not enough.

Troubleshooting systemd and Permission Failures

If the timer exists but never starts the service, inspect the timer and journal together:

Terminal window
systemctl status certbot-renew.timer
systemctl status certbot-renew.service
journalctl -u certbot-renew.timer -u certbot-renew.service --since today

A failed unit often reports:

status=203/EXEC
Executable /usr/bin/certbot does not exist

Check the executable path:

Terminal window
command -v certbot
ls -l /usr/bin/certbot

Update the service unit, reload the daemon, and try again:

Terminal window
sudo systemctl daemon-reload
sudo systemctl start certbot-renew.service

Permission errors may look like this:

PermissionError: [Errno 13] Permission denied: '/etc/letsencrypt/live/example.com/privkey.pem'

The service must run as root unless a carefully designed least-privilege deployment assigns writable ownership to the necessary paths. The standard Certbot service runs as root, and the private key directory is normally restricted with mode 0700 or 0711 on the live parent directory. Do not make the private key world-readable.

Check the permissions without changing them blindly:

Terminal window
namei -l /etc/letsencrypt/live/example.com/privkey.pem
sudo ls -la /etc/letsencrypt/live/example.com

An AppArmor or SELinux denial can prevent the service from reading files or executing the deploy hook. Inspect the relevant service log or system audit log:

Terminal window
sudo journalctl -k --since today | grep -Ei 'apparmor|selinux|denied'
sudo ausearch -m avc -ts recent

Troubleshooting Hook Failures

A failed reload hook may report:

Running deploy hook: /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
Error while running reload-nginx.sh: Command '/usr/sbin/nginx -t' returned non-zero exit status 1
nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/example.com/fullchain.pem": PEM_read_bio_X509_Auto failed

The certificate was renewed, but the service could not load the new file. Run the validation command directly to see the full diagnostic:

Terminal window
sudo /usr/sbin/nginx -t

Check the symlink targets and certificate parsing:

Terminal window
readlink -f /etc/letsencrypt/live/example.com/fullchain.pem
sudo openssl x509 \
-in /etc/letsencrypt/live/example.com/fullchain.pem \
-noout

If the service reload fails after a successful renewal, Certbot can report a non-success result even though the new certificate exists. The deploy hook should be repaired and the service reloaded manually. Do not delete the renewal configuration simply because the hook failed.

Hooks receive environment variables supplied by Certbot. A hook can limit itself to one certificate by checking RENEWED_LINEAGE or RENEWED_DOMAINS:

#!/usr/bin/env bash
set -euo pipefail
if [[ "${RENEWED_LINEAGE:-}" == "/etc/letsencrypt/live/example.com" ]]; then
/usr/sbin/nginx -t
/usr/bin/systemctl reload nginx
fi

Use RENEWED_LINEAGE when the path is stable. RENEWED_DOMAINS contains a space-separated domain list and requires careful quoting.

Common Operational Mistakes

The most frequent mistake is pointing the application directly at /etc/letsencrypt/archive/.... The archive path contains version numbers that change after renewal. Configure Nginx, HAProxy, or another application to use the stable /etc/letsencrypt/live/... path.

Another mistake is relying on a cron entry without checking the exit status:

0 3 * * * certbot renew >> /var/log/certbot.log 2>&1

A systemd service provides structured status, timeout handling, and journal output. It also makes the operation visible to systemctl status certbot-renew.timer.

Do not combine an old cron renewal job with a systemd timer. Both can attempt renewal at the same time and create account throttling, rate-limit errors, or competing deploy hooks. Remove the old job after confirming the timer works:

Terminal window
crontab -l
sudo crontab -l

Check both the user’s crontab and the system-wide crontab. Some installations also use a systemd timer that was created by the Certbot package itself. List all matching units:

Terminal window
systemctl list-unit-files | grep -i certbot
systemctl list-timers --all | grep -i certbot

If a distribution package creates certbot.timer and you also create certbot-renew.timer, disable one of them to prevent duplicate checks.

Production Checklist

Before leaving the configuration unattended, verify every relevant condition from the command line.

Confirm that the certificate exists and covers the intended names:

Terminal window
sudo certbot certificates
sudo openssl x509 \
-in /etc/letsencrypt/live/example.com/fullchain.pem \
-noout \
-subject \
-issuer \
-dates

Run a forced staging renewal:

Terminal window
sudo certbot renew --dry-run --staging --force-renewal

Run the actual systemd service and inspect the result:

Terminal window
sudo systemctl start certbot-renew.service
systemctl status certbot-renew.service
journalctl -u certbot-renew.service --since today --no-pager

Confirm that the timer is enabled and scheduled:

Terminal window
systemctl is-enabled certbot-renew.timer
systemctl is-active certbot-renew.timer
systemctl list-timers certbot-renew.timer

Test the deploy hook independently:

Terminal window
sudo /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

Remove duplicate renewal mechanisms and set an independent expiration alert. A timer reduces manual work, but certificate monitoring is still necessary because an expired certificate can take a service offline even when systemd reports the timer as active.

Maintaining the Setup

Update Certbot through the same package source used during installation:

Terminal window
sudo apt update
sudo apt install --only-upgrade certbot

Or, on RHEL-family systems:

Terminal window
sudo dnf upgrade certbot

After upgrading, run a staging dry run and start the service once:

Terminal window
sudo certbot renew --dry-run --staging
sudo systemctl start certbot-renew.service

Keep the systemd units and deploy hooks under version control. A practical repository layout is:

certbot/
├── certbot-renew.service
├── certbot-renew.timer
└── renewal-hooks/
└── deploy/
└── reload-nginx.sh

Store API credentials outside the repository. On a single-purpose host, the secret can live in /etc/letsencrypt with restrictive permissions. On fleets, inject it through the configuration management system or a secrets platform and rotate it on a defined schedule.

After DNS, web-server, or firewall changes, rerun the staging renewal. After certificate-path or service-name changes, execute the deploy hook manually. These small checks catch the two most common causes of failed unattended renewal before a certificate reaches its renewal window.

found this useful? share it →
Written by

Dzubayyan Ahmad

System Administrator, SRE & Technical Support Engineer specialising in web hosting infrastructure — Linux servers, automation, and monitoring. Writing these notes since 2015 so future-me can find the fix again.