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.confThe 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.0archive_dir = /etc/letsencrypt/archive/example.comcert = /etc/letsencrypt/live/example.com/cert.pemprivkey = /etc/letsencrypt/live/example.com/privkey.pemchain = /etc/letsencrypt/live/example.com/chain.pemfullchain = /etc/letsencrypt/live/example.com/fullchain.pem
[renewalparams]authenticator = webrootwebroot_path = /var/www/htmlserver = https://acme-v02.api.letsencrypt.org/directoryThe 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:
dig +short example.com Adig +short www.example.com Adig +short api.example.com AIPv6 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:
sudo apt updatesudo apt install certbot python3-certbot-nginxInstall the Apache integration instead if Apache manages the site:
sudo apt updatesudo apt install certbot python3-certbot-apacheInstall only Certbot when a separate webroot or DNS plugin is enough:
sudo apt updatesudo apt install certbotOn RHEL, Fedora, and AlmaLinux, the available packages depend on the repository versions. Search for the package names before installing:
sudo dnf search certbotA common installation on RHEL-family systems uses the operating system packages:
sudo dnf install certbot python3-certbot-nginxFor the webroot plugin on a system where it is packaged separately:
sudo dnf install certbot python3-certbot-nginxOn Fedora, the package names may already be installed by a dependency chain. Confirm availability with:
dnf info certbotdnf info python3-certbot-nginxSome 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:
certbot --versioncommand -v certbotcertbot pluginsRecord 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:
sudo mkdir -p /var/www/html/.well-known/acme-challengesudo chown "$USER":"$USER" /var/www/html/.well-known/acme-challengeConfirm that the web server exposes that directory at the public URL:
printf 'certbot-test\n' > /var/www/html/.well-known/acme-challenge/testcurl -fsS http://example.com/.well-known/acme-challenge/testThe curl command should print:
certbot-testIf it returns a 404, inspect the virtual host configuration, document root, directory permissions, and any redirect rules.
Request a certificate with the webroot authenticator:
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-interactiveThe --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:
sudo certbot certonly --nginx \ --cert-name example.com \ --domains example.com,www.example.com \ --email admin@example.com \ --agree-tos \ --non-interactiveFor an Apache-managed site:
sudo certbot certonly --apache \ --cert-name example.com \ --domains example.com,www.example.com \ --email admin@example.com \ --agree-tos \ --non-interactiveFor a temporary standalone listener, stop the service that owns ports 80 and 443 before requesting the certificate:
sudo systemctl stop nginxsudo certbot certonly --standalone \ --cert-name example.com \ --domains example.com,www.example.com \ --email admin@example.com \ --agree-tos \ --non-interactivesudo systemctl start nginxThe 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:
sudo certbot certificatessudo openssl x509 \ -in /etc/letsencrypt/live/example.com/fullchain.pem \ -noout \ -subject \ -issuer \ -datesThe 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:
sudo certbot renew \ --dry-run \ --staging \ --cert-name example.comA 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:
sudo certbot renew \ --dry-run \ --staging \ --force-renewal \ --cert-name example.comRun 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 certificatesDocumentation=https://eff-certbot.readthedocs.io/After=network-online.targetWants=network-online.target
[Service]Type=oneshotExecStart=/usr/bin/certbot renew --quietCheck the Certbot path before using this unit:
command -v certbotIf 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 bashset -euo pipefail
/usr/bin/systemctl reload nginxMake the script executable:
sudo chmod 0750 /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.shThe 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:
sudo /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.shsudo systemctl status nginxFor 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 dailyDocumentation=https://eff-certbot.readthedocs.io/
[Timer]OnCalendar=*-*-* 03,15:00:00RandomizedDelaySec=3600Persistent=true
[Install]WantedBy=timers.targetThis 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:
sudo systemctl daemon-reloadsudo systemctl enable --now certbot-renew.timerCheck its state:
systemctl list-timers certbot-renew.timersystemctl status certbot-renew.timerA healthy timer should show the next expected run. If the timer shows no future trigger, run:
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:00AccuracySec=1minPersistent=trueRunning the Timer Manually
Test the service directly before waiting for the timer:
sudo systemctl start certbot-renew.servicesystemctl status certbot-renew.serviceFor scripts and CI checks, the command returns a nonzero status when the service fails:
sudo systemctl start certbot-renew.serviceInspect the journal:
journalctl -u certbot-renew.service \ --since today \ --no-pagerThe 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:
systemctl status certbot-renew.timerjournalctl -u certbot-renew.timer --since today --no-pagerA 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 bashset -euo pipefail
/usr/sbin/nginx -t/usr/bin/systemctl reload nginxSave it as /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh:
sudo chmod 0750 /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.shFor Apache, use:
#!/usr/bin/env bashset -euo pipefail
/usr/sbin/apachectl configtest/usr/bin/systemctl reload apache2On RHEL-family systems, the Apache service is commonly named httpd:
#!/usr/bin/env bashset -euo pipefail
/usr/sbin/httpd -t/usr/bin/systemctl reload httpdHAProxy can validate its configuration with:
#!/usr/bin/env bashset -euo pipefail
/usr/sbin/haproxy -c -f /etc/haproxy/haproxy.cfg/usr/bin/systemctl reload haproxyA 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 bashset -euo pipefail
/usr/bin/systemctl restart my-applicationRestarting 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:
sudo certbot certificatesInspect individual renewal configurations:
sudo cat /etc/letsencrypt/renewal/example.com.confA systemd timer can run the general renewal command:
ExecStart=/usr/bin/certbot renew --quietFor 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=oneshotExecStart=/usr/bin/certbot renew --quiet --cert-name example.comThen give each timer a distinct name:
certbot-example-com.servicecertbot-example-com.timerThis 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:
apt-cache search certbot-dns | grep -i providerFor 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:
sudo install -d -m 0700 /etc/letsencryptsudo sh -c 'cat > /etc/letsencrypt/cloudflare.ini' <<'EOF'dns_cloudflare_api_token = YOUR_RESTRICTED_API_TOKENEOFsudo chmod 0600 /etc/letsencrypt/cloudflare.iniUse 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:
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-interactiveThe 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.
sudo certbot renew \ --dry-run \ --staging \ --force-renewalDo 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 --quietIf 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:
sudo certbot show_accountLogging and Monitoring
The systemd journal is the primary log source on hosts using systemd. A simple monitoring check can look for failed renewal services:
systemctl is-failed certbot-renew.serviceFor 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 bashset -euo pipefail
certificate=/etc/letsencrypt/live/example.com/fullchain.pemexpiration_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"fiThis 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:
sudo certbot renew --dry-run --verboseThe 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:connectionFailed authorization for example.comurn:ietf:params:acme:error:connection: 400 :: urn:ietf:params:acme:error:connection :: dns :: NXDOMAIN looking up A for example.comThis 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:
dig +short example.com Acurl -I http://example.com/.well-known/acme-challenge/testA different error points to a missing challenge file:
Detail: The keyauthorization file from the server did not match this challengeCompare 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.comurn:ietf:params:acme:error:unauthorized: 400 :: urn:ietf:params:acme:error:unauthorized :: Invalid response from http://example.com/.well-known/acme-challenge/token: 404The 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.comRecheck the record from public resolvers:
dig +short TXT _acme-challenge.example.com @1.1.1.1Wait 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:
systemctl status certbot-renew.timersystemctl status certbot-renew.servicejournalctl -u certbot-renew.timer -u certbot-renew.service --since todayA failed unit often reports:
status=203/EXECExecutable /usr/bin/certbot does not existCheck the executable path:
command -v certbotls -l /usr/bin/certbotUpdate the service unit, reload the daemon, and try again:
sudo systemctl daemon-reloadsudo systemctl start certbot-renew.servicePermission 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:
namei -l /etc/letsencrypt/live/example.com/privkey.pemsudo ls -la /etc/letsencrypt/live/example.comAn 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:
sudo journalctl -k --since today | grep -Ei 'apparmor|selinux|denied'sudo ausearch -m avc -ts recentTroubleshooting Hook Failures
A failed reload hook may report:
Running deploy hook: /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.shError while running reload-nginx.sh: Command '/usr/sbin/nginx -t' returned non-zero exit status 1nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/example.com/fullchain.pem": PEM_read_bio_X509_Auto failedThe certificate was renewed, but the service could not load the new file. Run the validation command directly to see the full diagnostic:
sudo /usr/sbin/nginx -tCheck the symlink targets and certificate parsing:
readlink -f /etc/letsencrypt/live/example.com/fullchain.pemsudo openssl x509 \ -in /etc/letsencrypt/live/example.com/fullchain.pem \ -nooutIf 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 bashset -euo pipefail
if [[ "${RENEWED_LINEAGE:-}" == "/etc/letsencrypt/live/example.com" ]]; then /usr/sbin/nginx -t /usr/bin/systemctl reload nginxfiUse 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>&1A 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:
crontab -lsudo crontab -lCheck 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:
systemctl list-unit-files | grep -i certbotsystemctl list-timers --all | grep -i certbotIf 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:
sudo certbot certificatessudo openssl x509 \ -in /etc/letsencrypt/live/example.com/fullchain.pem \ -noout \ -subject \ -issuer \ -datesRun a forced staging renewal:
sudo certbot renew --dry-run --staging --force-renewalRun the actual systemd service and inspect the result:
sudo systemctl start certbot-renew.servicesystemctl status certbot-renew.servicejournalctl -u certbot-renew.service --since today --no-pagerConfirm that the timer is enabled and scheduled:
systemctl is-enabled certbot-renew.timersystemctl is-active certbot-renew.timersystemctl list-timers certbot-renew.timerTest the deploy hook independently:
sudo /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.shRemove 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:
sudo apt updatesudo apt install --only-upgrade certbotOr, on RHEL-family systems:
sudo dnf upgrade certbotAfter upgrading, run a staging dry run and start the service once:
sudo certbot renew --dry-run --stagingsudo systemctl start certbot-renew.serviceKeep 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.shStore 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.