← All cheatsheets

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 you
Test renewalcertbot renew --dry-runSimulate renewal against LE staging (generous rate limits — won't burn production quota)
Inspect live chainopenssl s_client -connect DOMAIN:443 -servername DOMAIN -showcertsSee served chain, SNI, and handshake errors
Cert datesopenssl x509 -in CERT.pem -noout -dates -subject -issuernotBefore/notAfter, CN/SAN subject, issuer
Expiry one-linerecho | openssl s_client -connect DOMAIN:443 -servername DOMAIN 2>/dev/null | openssl x509 -noout -enddateJust the notAfter of the served leaf

TLS chain of trust and how ACME issues the leaf

TLS chain of trust and ACME issuanceRoot CA signs Intermediate CA signs Leaf; server serves fullchain; client validates to a trusted root; certbot proves control via HTTP-01 or DNS-01.Root CAin trust storeIntermediate CAserved by youLeaf certyour domain, SAN, 90dsignssignsclient validates chain upward to a trusted root (Verify return code: 0)certbot / ACME — prove domain control, then issue the leafHTTP-01: serve a token at http://DOMAIN/.well-known/acme-challenge/ (needs :80)DNS-01: publish _acme-challenge.DOMAIN TXT (works for *.wildcard, no :80)Auto-renew: certbot.timer runs twice daily -> certbot renew -> deploy-hook reloads server

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

IssueRenewInspect
Issue + install on nginx (HTTP-01)certbot --nginx -d example.com -d www.example.comls /etc/letsencrypt/live/example.com/ shows fullchain.pem + privkey.pem
Issue standalone (no web server running)certbot certonly --standalone -d example.comcertbot 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.comAdd the printed _acme-challenge TXT, then dig TXT _acme-challenge.example.com returns it
List managed certs + expirycertbot certificatesEach lineitem shows Domains, Expiry Date, and VALID: N days
Dry-run every renewalcertbot renew --dry-runOutput ends with 'Congratulations, all simulated renewals succeeded'
Force a real renewal nowcertbot renew --force-renewalNew notBefore via openssl x509 -in fullchain.pem -noout -dates
Confirm the auto-renew timer is armedsystemctl list-timers certbot.timerNEXT column shows an upcoming run (twice-daily)
Reload the server after renewalnginx -t && systemctl reload nginx'syntax is ok' then expiry one-liner shows the new date
Verify SAN names on a certopenssl x509 -in CERT.pem -noout -ext subjectAltNameX509v3 Subject Alternative Name lists every DNS: host you serve
Check served chain completenessopenssl s_client -connect DOMAIN:443 -servername DOMAIN -showcerts </dev/nullVerify return code: 0 (ok) and 2+ certs printed (leaf + intermediate)
Generate a CSR from an existing keyopenssl 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 certcertbot revoke --cert-path /etc/letsencrypt/live/example.com/cert.pem --reason keyCompromise && certbot delete --cert-name example.comcertbot 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 succeeded
3
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.pem
4
Reload the server so it picks up the new material
nginx -t && systemctl reload nginx
# nginx: configuration file ... test is successful
5
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

SymptomFirst checkEstablishesNext check
Browser: NET::ERR_CERT_DATE_INVALID / expiredecho | openssl s_client -connect DOMAIN:443 -servername DOMAIN 2>/dev/null | openssl x509 -noout -enddateWhether 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 missingServe fullchain.pem (leaf+intermediate), not cert.pem; reload server
Wrong cert served / name mismatch on a multi-site hostCompare openssl with and without SNI: add vs omit -servername DOMAINServer returns the default vhost cert when SNI is absent/misroutedFix the vhost server_name/SNI mapping so the right cert answers for DOMAIN
certbot renew --dry-run fails on HTTP-01curl -I http://DOMAIN/.well-known/acme-challenge/test from an outside hostPort 80 reachable and not redirected/firewalled before validationOpen :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.1Whether the challenge TXT is published and propagated at the authoritative DNSUse a DNS plugin (e.g. certbot-dns-*) for automation, or raise propagation wait
Self-signed / untrusted-root error in a dev or internal environmentopenssl x509 -in CERT.pem -noout -issuer -subjectissuer == subject means self-signed; or issuer is a private CA not in the trust storeInstall the CA into the client trust store, or obtain a publicly-trusted cert for a real domain