Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

certbot

Get free TLS certificates from Let's Encrypt and renew them automatically.

Level
DevSecOps service
Group
Web
Needs root
Yes
Package
certbot

What it does

Certbot speaks the ACME protocol with Let's Encrypt: it proves you control a domain (an HTTP file or a DNS record), gets a certificate valid for 90 days, can install it into nginx or Apache, and renews it with a timer before it expires. On RHEL, install it from EPEL (certbot, python3-certbot-nginx, python3-certbot-apache).

Certificates live in /etc/letsencrypt/live/DOMAIN/ (fullchain.pem, privkey.pem).

How to write it

certbot [SUBCOMMAND] [OPTION]...
certbot certonly --webroot -w DIR -d DOMAIN

Main parts

Subcommands

run (default)
Get a certificate and install it.
certonly
Only get the certificate.
renew
Renew all certificates that expire soon.
certificates
List certificates and their expiry dates.
delete --cert-name NAME
Delete a certificate.
revoke --cert-path FILE
Revoke a certificate.
reconfigure
Change the renewal settings.
register / update_account / unregister
Manage the ACME account.

Options 14

Most used

Main options

-d DOMAIN
A domain name (repeat for more names).
--nginx / --apache
Use the web-server plugin to prove and install.
--webroot -w DIR
Prove by writing a file into the web root.
--standalone
Start a small own web server on port 80.
--manual / --preferred-challenges dns
Prove with a DNS TXT record.
--dns-PLUGIN
Use a DNS provider plugin (cloudflare, route53, …).
--cert-name NAME
Name of the certificate lineage.
--email MAIL / --agree-tos / -n
Account email, accept terms, no questions.
--staging / --test-cert
Use the Let's Encrypt staging server.
--dry-run
Test renew or certonly without saving.
--key-type rsa|ecdsa / --rsa-key-size N
Key type and size.
--deploy-hook CMD
Command to run after a successful renewal.
--force-renewal
Renew now even if not due.
--expand
Add names to an existing certificate.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Install on RHEL

    dnf install -y epel-release
    dnf install -y certbot python3-certbot-nginx
  2. 2Get and install a certificate for nginx

    certbot --nginx -d shop.example.com -d www.shop.example.com --email admin@example.com --agree-tos -n
  3. 3Only get the certificate with the webroot method

    certbot certonly --webroot -w /srv/www/shop -d shop.example.com
  4. 4Get a wildcard certificate with a DNS challenge

    certbot certonly --manual --preferred-challenges dns -d '*.example.com' -d example.com
  5. 5Test on staging first

    certbot certonly --staging --nginx -d test.example.com
  6. 6List certificates and expiry dates

    certbot certificates
  7. 7Test and run the renewal

    certbot renew --dry-run
    systemctl list-timers | grep certbot
    certbot renew --deploy-hook "systemctl reload nginx"
  8. 8Use the files in a server config

    cat /etc/nginx/conf.d/shop-tls.conf
    ssl_certificate     /etc/letsencrypt/live/shop.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/shop.example.com/privkey.pem;
  9. 9Check the certificate from outside

    echo | openssl s_client -connect shop.example.com:443 -servername shop.example.com 2>/dev/null | openssl x509 -noout -dates -issuer
  10. 10Revoke and delete a certificate

    certbot revoke --cert-name shop.example.com
    certbot delete --cert-name shop.example.com

Watch out

  • Let's Encrypt has rate limits; test with --staging.
  • Keep /etc/letsencrypt/ backed up and private: it contains the private keys.
  • The HTTP challenge needs port 80 open from the internet.

Files

/etc/letsencrypt/live/DOMAIN/
Current certificate files (links).
/etc/letsencrypt/renewal/DOMAIN.conf
Renewal settings.
/var/log/letsencrypt/letsencrypt.log
Log.

Tips to remember

  • In Kubernetes use cert-manager instead; for Traefik/Caddy the proxy does ACME itself.

Exit codes

0Success.
1Error.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man certbot