Introduction
Certbot requests, installs, and renews Let’s Encrypt TLS certificates without manual intervention. This guide covers installation, certificate issuance for Nginx and Apache, renewal automation via systemd timers, and common failure scenarios with their fixes.
Install Certbot
Use your distro’s package manager. Snap is the officially recommended method and keeps Certbot updated independently of the OS release cycle.
# Remove any OS-packaged certbot firstsudo apt remove certbot 2>/dev/nullsudo dnf remove certbot 2>/dev/null
# Install via snap (Ubuntu, Debian, Fedora, RHEL, Arch)sudo snap install --classic certbotsudo ln -s /snap/bin/certbot /usr/bin/certbotVerify the installation:
certbot --versionIf your server does not support snap (minimal containers, older distros), install via pip in a virtual environment:
sudo python3 -m venv /opt/certbotsudo /opt/certbot/bin/pip install certbot certbot-nginxsudo ln -s /opt/certbot/bin/certbot /usr/bin/certbotThe pip route requires you to run pip install --upgrade certbot yourself. Snap handles that automatically.
Obtain a Certificate
Nginx
sudo certbot --nginx -d example.com -d www.example.comCertbot reads your Nginx server blocks, proves domain ownership over HTTP-01, fetches the certificate, and rewrites the relevant server {} block to add ssl_certificate, ssl_certificate_key, and a 301 redirect from port 80.
Apache
sudo certbot --apache -d example.com -d www.example.comSame flow. Certbot modifies the VirtualHost and creates an SSL VirtualHost if one does not exist.
Standalone (No Web Server Running)
If nothing listens on port 80, Certbot can spin up its own temporary server:
sudo certbot certonly --standalone -d example.comThis fails if another process already binds port 80. Stop it first or use the webroot method instead.
Webroot (Web Server You Do Not Want Certbot to Touch)
Point Certbot at your existing document root:
sudo certbot certonly --webroot -w /var/www/html -d example.comCertbot places a challenge file under /var/www/html/.well-known/acme-challenge/, and Let’s Encrypt verifies it over HTTP. Your web server config stays untouched.
Where Certificates Land
Certbot stores everything under /etc/letsencrypt/:
/etc/letsencrypt/├── live/│ └── example.com/│ ├── fullchain.pem # cert + intermediate chain│ ├── privkey.pem # private key│ ├── cert.pem # server cert only│ └── chain.pem # intermediate only├── archive/ # versioned copies└── renewal/ # renewal config per domain └── example.com.confPoint your web server or application at the live/ symlinks. They always resolve to the latest version after renewal.
Automatic Renewal
Certbot’s snap package installs a systemd timer that runs certbot renew twice daily. Certificates renew only when they are within 30 days of expiry, so the frequent schedule is harmless.
Check the timer status:
sudo systemctl list-timers | grep certbotYou should see snap.certbot.renew.timer (or certbot.timer on pip installs that ship a unit file). If the timer is missing, create one:
[Unit]Description=Certbot renewal timer
[Timer]OnCalendar=*-*-* 02,14:30:00RandomizedDelaySec=3600Persistent=true
[Install]WantedBy=timers.target[Unit]Description=Certbot renewal
[Service]Type=oneshotExecStart=/usr/bin/certbot renew --quietsudo systemctl daemon-reloadsudo systemctl enable --now certbot-renew.timerPost-Renewal Hooks
Certbot renews the files on disk, but your web server still holds the old certificate in memory until it reloads. Add a deploy hook so the reload happens automatically:
sudo certbot renew --deploy-hook "systemctl reload nginx"To make the hook permanent for a specific certificate, edit /etc/letsencrypt/renewal/example.com.conf and add under [renewalparams]:
[renewalparams]renew_hook = systemctl reload nginxFor Apache, replace with systemctl reload apache2 (or httpd on RHEL-family systems).
Dry Run
Test renewal without actually contacting Let’s Encrypt:
sudo certbot renew --dry-runThis exercises the full flow (including hooks) against the Let’s Encrypt staging server. Run it after any config change.
Rate Limits
Let’s Encrypt enforces production rate limits. The ones you will hit first:
| Limit | Value |
|---|---|
| Certificates per registered domain per week | 50 |
| Duplicate certificates per week | 5 |
| Failed authorizations per hostname per hour | 5 |
During testing, use the staging environment to avoid burning through limits:
sudo certbot certonly --nginx --staging -d example.comStaging certificates are not trusted by browsers, but the ACME flow is identical. Remove --staging for production.
Wildcard Certificates
Wildcard certs (*.example.com) require DNS-01 validation. Certbot needs a plugin for your DNS provider. Example with Cloudflare:
sudo snap install certbot-dns-cloudflare
# Create credentials filesudo mkdir -p /etc/letsencrypt/cloudflarecat <<EOF | sudo tee /etc/letsencrypt/cloudflare/credentials.inidns_cloudflare_api_token = YOUR_API_TOKEN_HEREEOFsudo chmod 600 /etc/letsencrypt/cloudflare/credentials.ini
sudo certbot certonly \ --dns-cloudflare \ --dns-cloudflare-credentials /etc/letsencrypt/cloudflare/credentials.ini \ -d "*.example.com" \ -d example.comThe Cloudflare API token needs Zone:DNS:Edit permission for the target zone. Scoped tokens are safer than global API keys.
DNS plugins exist for Route 53, DigitalOcean, Google Cloud DNS, Linode, and others. Install the matching certbot-dns-* snap or pip package.
Troubleshooting
Challenge Failed: Connection Refused
Challenge failed for domain example.com Fetching http://example.com/.well-known/acme-challenge/xxxx: Connection refusedRoot cause: Let’s Encrypt cannot reach port 80 on your server. Check that port 80 is open in your firewall and that your DNS A/AAAA record points to the correct IP.
# Check firewallsudo ufw status # Ubuntusudo firewall-cmd --list-all # RHEL/Fedora
# Check DNS resolutiondig +short example.comcurl -I http://example.com/.well-known/acme-challenge/testToo Many Certificates Already Issued
Error creating new order :: too many certificates (5) already issued for thisexact set of domains in the last 168 hoursWait a week, or add/remove a SAN to change the “exact set” and issue a new certificate. Use --staging for testing.
Permission Denied on Renewal
Could not open file: /etc/letsencrypt/archive/example.com/privkey3.pem -Permission deniedThe renewal runs as root via the systemd timer. If you ran certbot as a different user during setup, ownership may be mixed. Fix it:
sudo chown -R root:root /etc/letsencryptsudo chmod -R 600 /etc/letsencrypt/archive/sudo chmod -R 700 /etc/letsencrypt/live/ /etc/letsencrypt/archive/Nginx Config Test Fails After Renewal
nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/example.com/fullchain.pem"The symlink in live/ is broken, usually because someone manually deleted files in archive/. Reissue:
sudo certbot delete --cert-name example.comsudo certbot --nginx -d example.com -d www.example.comDNS-01 Challenge Timeout (Wildcard)
Waiting for verification...Challenge failed for domain *.example.comdns-01 challenge :: DNS problem: NXDOMAIN looking up TXT for _acme-challenge.example.comThe TXT record was not created or has not propagated. Increase the propagation wait:
sudo certbot certonly \ --dns-cloudflare \ --dns-cloudflare-credentials /etc/letsencrypt/cloudflare/credentials.ini \ --dns-cloudflare-propagation-seconds 60 \ -d "*.example.com"Verify the record manually:
dig TXT _acme-challenge.example.com +shortRevoking and Deleting Certificates
If a private key is compromised:
sudo certbot revoke --cert-name example.com --reason keycompromisesudo certbot delete --cert-name example.comRevocation notifies Let’s Encrypt immediately. delete removes the local files and renewal config.
Checking Certificate Expiry
Quick check from the command line:
sudo certbot certificatesFrom a remote machine:
echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null \ | openssl x509 -noout -datesBoth show notBefore and notAfter. If notAfter is less than 30 days out and the timer is active, renewal should happen automatically on the next run. If it does not, run certbot renew --dry-run and read the error output.