هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
Let's Encrypt must see that you control the domain (a challenge). HTTP-01: Certbot puts a file under http://DOMAIN/.well-known/acme-challenge/ — port 80 must be open from the internet. DNS-01: Certbot creates a TXT record — needed for wildcards (*.example.com) and for servers that are not public.
| Item | Value |
|---|---|
| Packages | certbot + a plugin: python3-certbot-nginx, python3-certbot-apache, python3-certbot-dns-… |
| Certificates | /etc/letsencrypt/live/DOMAIN/fullchain.pem and privkey.pem (links to archive/) |
| Renewal settings | /etc/letsencrypt/renewal/DOMAIN.conf |
| Hooks | /etc/letsencrypt/renewal-hooks/{pre,post,deploy}/ |
| Renewal timer | certbot-renew.timer (RHEL/EPEL), certbot.timer (Ubuntu apt), snap.certbot.renew.timer (snap) |
| Logs | /var/log/letsencrypt/letsencrypt.log |
| Ports | 80/tcp for HTTP-01 (also when the site is HTTPS only) |
تذكّر
Let's Encrypt certificates last 90 days (and will get shorter in the next years). Renewal must be automatic. Let's Encrypt no longer sends expiry warning emails, so watch the expiry dates yourself.
Install on RHEL, Rocky, Alma and Fedora
Certbot comes from EPEL:
dnf -y install epel-release
dnf -y install certbot python3-certbot-nginx python3-certbot-apache
systemctl enable --now certbot-renew.timer
systemctl list-timers | grep certbotOn RHEL itself (not Rocky/Alma) install EPEL with dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm and enable CodeReady Builder. Fedora has Certbot in its own repos.
Install on Ubuntu and Debian
apt-get update
apt-get install -y certbot python3-certbot-nginx python3-certbot-apache
systemctl list-timers | grep certbotThe Certbot team recommends the snap (always the newest version): snap install --classic certbot and ln -s /snap/bin/certbot /usr/bin/certbot. Use one way only, not both.
Get a certificate
Before you start: the DNS A/AAAA records point to this server, port 80 is open, and the web server has a server_name / ServerName for the domain. Test against the staging server first (no rate limits), then get the real one:
certbot --nginx -d shop.example.com -d www.shop.example.com --staging
certbot --nginx -d shop.example.com -d www.shop.example.com --email ops@example.com --agree-tos --redirect
certbot --apache -d intranet.example.comCertbot changes the server config (adds the certificate and the HTTP → HTTPS redirect) and reloads it. Without changing the config — only get the files:
certbot certonly --webroot -w /var/www/shop -d shop.example.com
certbot certonly --standalone -d mail.example.com--webroot uses a running web server's folder; --standalone starts its own small web server on port 80 (stop the other one first).
Wildcards with DNS-01
With a DNS plugin for your provider (Cloudflare, Route 53, Google, …), Certbot writes the TXT record itself:
dnf -y install python3-certbot-dns-cloudflare
install -m 600 /dev/null /etc/letsencrypt/cloudflare.ini
vim /etc/letsencrypt/cloudflare.ini
certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini -d 'example.com' -d '*.example.com'The .ini file holds an API token that may only edit DNS of this zone (dns_cloudflare_api_token = …). Keep it 600.
First configuration: make renewal safe
- Test the renewal of all certificates:
certbot renew --dry-run
Congratulations, all simulated renewals succeeded- Reload the web server after every renewal (the
--nginx/--apacheplugins do it; forcertonlyyou need a hook):
#!/bin/sh
systemctl reload nginxchmod 755 /etc/letsencrypt/renewal-hooks/deploy/reload-web.sh- Check the expiry yourself — in monitoring, or a simple test (exit code 1 when the certificate ends within 14 days):
echo | openssl s_client -connect shop.example.com:443 -servername shop.example.com 2>/dev/null | openssl x509 -noout -enddate -checkend 1209600
notAfter=Feb 14 08:12:55 2027 GMT
Certificate will not expire- Add a CAA DNS record so only Let's Encrypt may issue for your domain:
example.com. CAA 0 issue "letsencrypt.org".
Daily use: the commands and the real uses
certbot certificates
certbot renew
certbot renew --cert-name shop.example.com --force-renewal
certbot --nginx -d shop.example.com -d api.shop.example.com --expand
certbot revoke --cert-name old.example.com
certbot delete --cert-name old.example.com
tail -50 /var/log/letsencrypt/letsencrypt.logReal uses at work:
- HTTPS for every Nginx/Apache site, mail server and admin panel.
- Wildcard certificates with DNS-01 for many subdomains.
- In Kubernetes, cert-manager does the same job (ACME issuers) — the ideas are the same.
Make it safe
Security checklist:
/etc/letsencrypt/holds private keys: root only, in backups, never in Git.- DNS API tokens limited to one zone and DNS edit only; file mode
600. - Test with
--stagingto avoid rate limits;renew --dry-runafter every change. - A timer for renewal and an independent expiry check in monitoring.
- CAA record; strong TLS settings in the web server (TLS 1.2+, HSTS).
- Revoke and delete certificates of domains you no longer use.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
Timeout during connect (likely firewall problem) | Port 80 is closed from the internet. | Open 80/tcp in the firewall and cloud security group. |
DNS problem: NXDOMAIN looking up A for … | The DNS record does not exist yet. | Create it; wait; check with dig +short shop.example.com. |
Invalid response from http://…/.well-known/acme-challenge/…: 404 | Another server block or a redirect catches the request. | Make the challenge path reachable on port 80; check server_name. |
too many certificates already issued | Let's Encrypt rate limit. | Wait a week; use --staging for tests; reuse existing certificates. |
| Renewed, but the browser shows the old certificate | The web server was not reloaded. | Add a deploy hook; systemctl reload nginx. |
Could not bind TCP port 80 with --standalone | Nginx or Apache uses port 80. | Use --nginx/--webroot, or stop the server during the request. |
CAA record … prevents issuance | CAA allows another CA only. | Add issue "letsencrypt.org" to the CAA record. |
Next steps
- Quick how-tos: Get a free TLS certificate with Let's Encrypt, Check when a TLS certificate expires, Redirect HTTP to HTTPS in Nginx.
- Command pages: certbot, openssl, dig.
- Certbot at work: Free TLS certificates, Certbot in DevOps.
- The web servers: Install and set up Nginx, Install and set up Apache httpd.
- Practise: Lab: web, proxy and TLS.
1Why must port 80 stay open even when the site is HTTPS only?
The HTTP-01 challenge of Let's Encrypt comes over port 80.
2Which challenge do you need for *.example.com?
DNS-01 — wildcards can only be checked with a DNS TXT record.