Security
TLS Certificates & Lets Encrypt — issue, renew, and debug
Issue, auto-renew, and debug TLS certificates with certbot/ACME and openssl: read the chain (leaf → intermediate → root), pick HTTP-01 vs DNS-01, inspect expiry, and fix the usual broken-chain and renewal failures fast.
Docs-checkedtlssslcertificateslets-encryptcertbot
Quick reference — reach for these first
Issue (nginx)
certbot --nginx -d DOMAINObtain + install a cert and edit nginx for youTest renewal
certbot renew --dry-runSimulate renewal against LE staging (generous rate limits — won't burn production quota)Inspect live chain
openssl s_client -connect DOMAIN:443 -servername DOMAIN -showcertsSee served chain, SNI, and handshake errorsCert dates
openssl x509 -in CERT.pem -noout -dates -subject -issuernotBefore/notAfter, CN/SAN subject, issuerExpiry one-liner
echo | openssl s_client -connect DOMAIN:443 -servername DOMAIN 2>/dev/null | openssl x509 -noout -enddateJust the notAfter of the served leafTLS chain of trust and how ACME issues the leaf
Text equivalent: A left-to-right chain: a Root CA in the browser/OS trust store signs an Intermediate CA, which signs your Leaf (server) certificate. The server sends fullchain = leaf + intermediate during the handshake; the client walks up to the trusted root to validate. Below, certbot/ACME proves domain control via HTTP-01 (port 80 file) or DNS-01 (TXT record) to obtain the leaf, valid 90 days and auto-renewed by a timer.
Common tasks
Issue · Renew · Inspect
| Issue | Renew | Inspect |
|---|---|---|
| Issue + install on nginx (HTTP-01) | certbot --nginx -d example.com -d www.example.com | ls /etc/letsencrypt/live/example.com/ shows fullchain.pem + privkey.pem |
| Issue standalone (no web server running) | certbot certonly --standalone -d example.com | certbot binds :80 itself; cert appears under live/example.com/ |
| Issue a wildcard (DNS-01 required) | certbot certonly --manual --preferred-challenges dns -d '*.example.com' -d example.com | Add the printed _acme-challenge TXT, then dig TXT _acme-challenge.example.com returns it |
| List managed certs + expiry | certbot certificates | Each lineitem shows Domains, Expiry Date, and VALID: N days |
| Dry-run every renewal | certbot renew --dry-run | Output ends with 'Congratulations, all simulated renewals succeeded' |
| Force a real renewal now | certbot renew --force-renewal | New notBefore via openssl x509 -in fullchain.pem -noout -dates |
| Confirm the auto-renew timer is armed | systemctl list-timers certbot.timer | NEXT column shows an upcoming run (twice-daily) |
| Reload the server after renewal | nginx -t && systemctl reload nginx | 'syntax is ok' then expiry one-liner shows the new date |
| Verify SAN names on a cert | openssl x509 -in CERT.pem -noout -ext subjectAltName | X509v3 Subject Alternative Name lists every DNS: host you serve |
| Check served chain completeness | openssl s_client -connect DOMAIN:443 -servername DOMAIN -showcerts </dev/null | Verify return code: 0 (ok) and 2+ certs printed (leaf + intermediate) |
| Generate a CSR from an existing key | openssl req -new -key privkey.pem -out example.csr -subj '/CN=example.com' | openssl req -in example.csr -noout -verify prints 'verify OK' |
| Add a renew-deploy hook (reload on success) | certbot renew --deploy-hook 'systemctl reload nginx' | ls /etc/letsencrypt/renewal-hooks/deploy/ or the renewal .conf lists the hook |
| [PROD] Revoke + delete a compromised cert | certbot revoke --cert-path /etc/letsencrypt/live/example.com/cert.pem --reason keyCompromise && certbot delete --cert-name example.com | certbot certificates no longer lists example.com |
A cert is about to expire and clients report a broken chain — diagnose, renew, verify
incident
1
Read what the server actually serves — dates and how many certs are in the chain
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null | openssl x509 -noout -dates -issuer
# notAfter=Nov 20 2026 ... issuer=C=US, O=Lets Encrypt, CN=R11 (expires in 6 days; only 1 cert returned => intermediate missing)2
Confirm the renewal path works before touching production (uses LE staging — generous rate limits, not unlimited)
certbot renew --dry-run
# Congratulations, all simulated renewals succeeded3
Renew for real and point the server at the FULL chain, not the bare leaf
certbot renew --force-renewal # then ensure nginx uses fullchain.pem, not cert.pem
# Renewed: /etc/letsencrypt/live/example.com/fullchain.pem4
Reload the server so it picks up the new material
nginx -t && systemctl reload nginx
# nginx: configuration file ... test is successful5
Evaluate the fix: fresh date AND a complete chain (leaf + intermediate, verify ok)
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null | grep -E 'Verify return code|BEGIN CERTIFICATE' | sort | uniq -c
# 2 -----BEGIN CERTIFICATE----- # 1 Verify return code: 0 (ok) -> chain complete, trusted. (Optional: confirm with an external scan such as SSL Labs.)Troubleshooting — symptom → first check → next check
| Symptom | First check | Establishes | Next check |
|---|---|---|---|
| Browser: NET::ERR_CERT_DATE_INVALID / expired | echo | openssl s_client -connect DOMAIN:443 -servername DOMAIN 2>/dev/null | openssl x509 -noout -enddate | Whether notAfter is in the past (renewal silently stopped running) | certbot renew --force-renewal then reload the server; then fix why the timer missed it |
| Clients fail only on some devices: 'unable to get local issuer certificate' | openssl s_client -connect DOMAIN:443 -servername DOMAIN -showcerts </dev/null | grep -c 'BEGIN CERTIFICATE' | Incomplete chain — only the leaf is served, intermediate missing | Serve fullchain.pem (leaf+intermediate), not cert.pem; reload server |
| Wrong cert served / name mismatch on a multi-site host | Compare openssl with and without SNI: add vs omit -servername DOMAIN | Server returns the default vhost cert when SNI is absent/misrouted | Fix the vhost server_name/SNI mapping so the right cert answers for DOMAIN |
| certbot renew --dry-run fails on HTTP-01 | curl -I http://DOMAIN/.well-known/acme-challenge/test from an outside host | Port 80 reachable and not redirected/firewalled before validation | Open :80 inbound (keep the HTTP vhost for the challenge) or switch to DNS-01 |
| DNS-01 renewal fails: 'no TXT record found' | dig +short TXT _acme-challenge.DOMAIN @1.1.1.1 | Whether the challenge TXT is published and propagated at the authoritative DNS | Use a DNS plugin (e.g. certbot-dns-*) for automation, or raise propagation wait |
| Self-signed / untrusted-root error in a dev or internal environment | openssl x509 -in CERT.pem -noout -issuer -subject | issuer == subject means self-signed; or issuer is a private CA not in the trust store | Install the CA into the client trust store, or obtain a publicly-trusted cert for a real domain |
References
- Lets Encrypt — Documentationletsencrypt.org
- Lets Encrypt — Challenge Types (HTTP-01 vs DNS-01)letsencrypt.org
- Certbot — User Guideeff-certbot.readthedocs.io
- OpenSSL — s_client manualdocs.openssl.org
- OpenSSL — x509 manualdocs.openssl.org