On this page
- What do I need before requesting a certificate?
- How do I install Certbot?
- How do I get a certificate with the Nginx or Apache plugin?
- When should I use the webroot method?
- How do I get a wildcard certificate with the DNS challenge?
- How does automatic renewal work?
- How do I check expiry and avoid rate limits?
- Why does validation fail?
- Questions
What do I need before requesting a certificate?
You need a domain whose DNS points at this server, a running web server and open web ports. Let's Encrypt validates by connecting to the name you request, so create A and AAAA records for every hostname first, as shown in DNS records, and wait until they resolve:
dig +short A example.net
dig +short AAAA example.netThe answers should be 198.51.100.24 and 2001:db8:4f2a::24. If an AAAA record exists, the site must answer on IPv6 too, because the validation servers prefer it. Then open the ports. On Ubuntu and Debian with UFW:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcpOn Rocky and Alma:
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reloadPort 80 must stay open even after you redirect everything to HTTPS, since the HTTP challenge uses it at every renewal.
How do I install Certbot?
Use the distribution package together with the plugin for your web server. On Ubuntu 24.04, 22.04 and Debian 12 or 13:
sudo apt update
sudo apt install certbot python3-certbot-nginx
# or for Apache
sudo apt install certbot python3-certbot-apache
certbot --versionOn Rocky Linux 9 and AlmaLinux 9 Certbot comes from EPEL:
sudo dnf install epel-release
sudo dnf install certbot python3-certbot-nginx
# or python3-certbot-apache
certbot --versionThe Certbot project also publishes a snap (sudo snap install --classic certbot) that tracks the newest release. Pick one source; having the apt or dnf package and the snap installed together causes two renewal jobs and confusing paths.
How do I get a certificate with the Nginx or Apache plugin?
The plugin finds the matching server_name or ServerName, answers the challenge and edits the config for you. Your site block must already contain the names you request:
sudo certbot --nginx -d example.net -d www.example.net
# Apache
sudo certbot --apache -d example.net -d www.example.netThe first run asks for an email address for account recovery and for agreement to the terms. Certbot then adds the certificate lines and, if you accept, an HTTP to HTTPS redirect. Check the result:
sudo nginx -t
curl -I https://example.net
sudo certbot certificatesNew certificates use ECDSA keys by default. If you have not set up the web server yet, start with the Nginx guide or the Apache guide.
When should I use the webroot method?
Use webroot when you want Certbot to leave your server config alone, or when the web server is something the plugins do not support. Certbot only drops a challenge file into a folder that the server already publishes:
sudo mkdir -p /var/www/example/.well-known/acme-challenge
sudo certbot certonly --webroot -w /var/www/example -d example.net -d www.example.netThe files land in /etc/letsencrypt/live/example.net/. Point your config at fullchain.pem and privkey.pem there, never at copies, so renewals take effect. For an app server behind a reverse proxy, serve /.well-known/acme-challenge/ from a fixed folder in the proxy config. If you would rather have certificates handled with no extra tool, the Caddy HTTPS tutorial shows a server that does it on its own.
How do I get a wildcard certificate with the DNS challenge?
Wildcards such as *.example.net require the DNS-01 challenge, where you prove control by publishing a TXT record. The manual mode works with any DNS host:
sudo certbot certonly --manual --preferred-challenges dns -d example.net -d "*.example.net"Certbot shows a value to publish as a TXT record at _acme-challenge.example.net. Add it, check from another terminal, then continue:
dig +short TXT _acme-challenge.example.netManual certificates do not renew on their own, because a person must add the record each time. For automatic renewal, use a DNS plugin that talks to your DNS host's API. Many hosts have a certbot-dns-* plugin; if you run your own BIND server, the RFC 2136 plugin (python3-certbot-dns-rfc2136) updates it with a TSIG key. Store plugin credentials in a file readable only by root (chmod 600).
How does automatic renewal work?
Let's Encrypt certificates are short lived (90 days for the default profile, with shorter lifetimes announced for the coming years), and Certbot renews well before expiry, so you never need to count days yourself. The packages install a systemd timer that runs twice a day. The unit name depends on the source:
# Ubuntu and Debian packages
systemctl list-timers certbot.timer
# EPEL on Rocky and Alma
sudo systemctl enable --now certbot-renew.timer
systemctl list-timers certbot-renew.timer
# snap
systemctl list-timers snap.certbot.renew.timerOn the RHEL family the timer is not always enabled after install, so the enable line matters. Test the whole renewal path against the staging service without touching your real certificates:
sudo certbot renew --dry-runPlugins reload Nginx or Apache after renewal. For other software that reads the files, put a script in /etc/letsencrypt/renewal-hooks/deploy/, for example one that runs systemctl reload haproxy, and make it executable.
How do I check expiry and avoid rate limits?
Let's Encrypt no longer emails expiry reminders, so monitor dates yourself. Two quick ways:
sudo certbot certificates
echo | openssl s_client -connect example.net:443 -servername example.net 2>/dev/null | openssl x509 -noout -datesAn uptime checker such as Uptime Kuma can also alert before a certificate expires. The service limits how many certificates you can issue for the same names in a week and how many failed validations you can make per hour. While experimenting, add --test-cert to use the staging environment, then request the real certificate once everything works.
Why does validation fail?
Most failures come from DNS or the firewall. Check that the A and AAAA records match this server, that ports 80 and 443 are open in UFW or firewalld, and that no old AAAA record points elsewhere. Read the exact error in /var/log/letsencrypt/letsencrypt.log. A 404 on the challenge path means the web server serves a different folder than the one Certbot wrote to; a timeout means the request never arrived. Test from outside with curl -I http://example.net/.well-known/acme-challenge/test; a 404 response is fine here, a timeout is not.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
| Plan | Fits because | Size | Monthly | Order from |
|---|---|---|---|---|
| A1-1 | Certbot runs fine on the smallest plan | 1 vCPU, 1 GB RAM, 25 GB NVMe | $3.60/mo | $43.20 for 12 months |
Questions about Free TLS certificates with Certbot
Are Let's Encrypt certificates really free?
Yes. They are domain validated certificates trusted by all major browsers and operating systems, issued at no cost by a nonprofit certificate authority.
Can I get a certificate for the bare IP address?
The usual route is a domain name. Point a hostname at the server with DNS records and request the certificate for that name.
Do I need port 80 open after switching to HTTPS?
For the HTTP challenge, yes. Keep port 80 open and redirect normal traffic to HTTPS; the challenge path still works.
Where are the certificate files?
In /etc/letsencrypt/live/your-domain/. Use fullchain.pem for the certificate and privkey.pem for the key.
What happens to certificates when I move to a bigger plan?
Copy the whole /etc/letsencrypt folder to the new server or simply request new certificates after the DNS change. See move to a larger plan.
More in Security
- UFW firewall on Ubuntu and Debian
- firewalld on Rocky Linux and AlmaLinux
- iptables rules that survive a reboot
- Block brute force logins with fail2ban
- CrowdSec intrusion prevention
- Two-factor SSH logins with TOTP
- Disable or restrict root login
- Alerts for every SSH login
- Advanced OpenSSH settings
- Publish SSH host keys in DNS (SSHFP)
- Audit open ports with nmap
- File integrity checks with AIDE and Tripwire
- CSF firewall (ConfigServer Security)
- First security steps on Rocky and Alma
- Self-signed certificates and a private CA
- Rate and connection limits in Nginx
- Wazuh security monitoring
- Kernel and sysctl hardening