متقدم
البحث فيأدلة التثبيت
طريقة البحث
  • الصق رسالة الخطأ بين علامتي تنصيص، مثل "permission denied"، لتجد جدول الحل.
  • اختر مجالًا وجزءًا من الدليل (التثبيت، أول الإعدادات، الاستخدام اليومي، الأمان، الحلول) لتصل مباشرة إلى الخطوة الصحيحة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدليل 26Certbot · Web

Install and set up Certbot (free Let's Encrypt certificates)

Certbot gets free TLS certificates from Let's Encrypt and renews them before they expire, so your sites stay on HTTPS without manual work. This guide installs Certbot on RHEL and Ubuntu, gets certificates for Nginx and Apache, explains the other methods (webroot, standalone, DNS for wildcards), and makes sure renewal really works — with a timer, a reload hook and your own expiry check.

  • 11 الدروس
  • 11 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

26.1

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.

ItemValue
Packagescertbot + 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 timercertbot-renew.timer (RHEL/EPEL), certbot.timer (Ubuntu apt), snap.certbot.renew.timer (snap)
Logs/var/log/letsencrypt/letsencrypt.log
Ports80/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.

الأوامر في هذا الدرس

26.2

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 certbot

On 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.

26.3

Install on Ubuntu and Debian

apt-get update
apt-get install -y certbot python3-certbot-nginx python3-certbot-apache
systemctl list-timers | grep certbot

The 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.

26.4

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.com

Certbot 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).

الأوامر في هذا الدرس

26.5

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.

26.6

First configuration: make renewal safe

  1. Test the renewal of all certificates:
certbot renew --dry-run
Congratulations, all simulated renewals succeeded
  1. Reload the web server after every renewal (the --nginx/--apache plugins do it; for certonly you need a hook):
/etc/letsencrypt/renewal-hooks/deploy/reload-web.sh
#!/bin/sh
systemctl reload nginx
chmod 755 /etc/letsencrypt/renewal-hooks/deploy/reload-web.sh
  1. 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
  1. Add a CAA DNS record so only Let's Encrypt may issue for your domain: example.com. CAA 0 issue "letsencrypt.org".

26.7

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.log

Real 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.

26.8

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 --staging to avoid rate limits; renew --dry-run after 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.

26.9

Update and remove

dnf -y upgrade certbot python3-certbot-nginx
apt-get install --only-upgrade -y certbot python3-certbot-nginx
snap refresh certbot
dnf -y remove certbot

Removing Certbot keeps /etc/letsencrypt/. Your sites keep working until the certificates expire — move them to another ACME client before that.

الأوامر في هذا الدرس

26.10

Fix common problems

ProblemCauseFix
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/…: 404Another server block or a redirect catches the request.Make the challenge path reachable on port 80; check server_name.
too many certificates already issuedLet's Encrypt rate limit.Wait a week; use --staging for tests; reuse existing certificates.
Renewed, but the browser shows the old certificateThe web server was not reloaded.Add a deploy hook; systemctl reload nginx.
Could not bind TCP port 80 with --standaloneNginx or Apache uses port 80.Use --nginx/--webroot, or stop the server during the request.
CAA record … prevents issuanceCAA allows another CA only.Add issue "letsencrypt.org" to the CAA record.

26.11

Next steps

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.

كل الأوامر في هذا الفصل