Tools › Cheat sheets › Networking & Security › Certbot (Let's Encrypt)
🔒

Certbot (Let's Encrypt) cheat sheet

Certbot automates getting certificates from Let's Encrypt. Your domain's DNS must point at the server (for HTTP challenges, ports 80 and 443 must be reachable). Most commands need sudo.

Click any command to copy it.

Get certificates

CommandWhat it does
sudo certbot --nginx -d example.com -d www.example.comObtain a certificate and configure nginx automatically.
sudo certbot --apache -d example.comSame for Apache.
sudo certbot certonly --standalone -d example.comGet a certificate using a temporary web server (port 80 must be free).
sudo certbot certonly --webroot -w /var/www/html -d example.comGet a certificate using your existing web root.
sudo certbot certonly --manual --preferred-challenges dns -d "*.example.com"Wildcard certificate using a DNS challenge.
sudo certbot --nginx -d example.com -n --agree-tos -m you@example.comNon-interactive issue for scripts.

Renew

CommandWhat it does
sudo certbot renew --dry-runTest renewal without changing anything.
sudo certbot renewRenew certificates that are close to expiry.
sudo certbot renew --deploy-hook "systemctl reload nginx"Reload the web server after a successful renewal.
systemctl list-timers | grep certbotCheck that automatic renewal is scheduled.

Inspect and manage

CommandWhat it does
sudo certbot certificatesList certificates, domains and expiry dates.
sudo certbot delete --cert-name example.comDestructive: Delete a certificate and its renewal configuration.
sudo certbot revoke --cert-path /etc/letsencrypt/live/example.com/cert.pemDestructive: Revoke a certificate.
sudo certbot --expand -d example.com -d new.example.comAdd another name to an existing certificate.
sudo certbot --nginx --redirect -d example.comAlso redirect HTTP to HTTPS.

Where files live

CommandWhat it does
/etc/letsencrypt/live/example.com/fullchain.pemCertificate plus chain; use as ssl_certificate.
/etc/letsencrypt/live/example.com/privkey.pemPrivate key; use as ssl_certificate_key.
/var/log/letsencrypt/letsencrypt.logDetailed log for troubleshooting failed issuance.

Frequently asked questions

Why did my certificate not renew?

Common causes are a changed firewall or DNS record, port 80 not reachable, or the web server config no longer serving the challenge. Run certbot renew --dry-run and read /var/log/letsencrypt/letsencrypt.log.

How long are Let's Encrypt certificates valid?

They are short-lived: 90 days at the time of writing, with shorter lifetimes planned. Run certbot certificates to see the exact expiry, and rely on automatic renewal rather than a fixed number.

More Networking & Security cheat sheets

🔑 SSH🌐 curl🛰️ Linux networking🛡️ ufw🔐 OpenSSL🌐 Subnet / CIDR🧱 iptablesAll Networking & Security cheat sheets →
Copied to clipboard