> ## Documentation Index
> Fetch the complete documentation index at: https://docs.1000w123.com/llms.txt
> Use this file to discover all available pages before exploring further.

# certbot

```bash theme={null}
sudo apt update
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx
```

验证 Certbot 是否正常运行。

```
$ certbot --version
certbot 2.6.0
```

生成 SSL 证书。

```
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m name@example.com -d bookwyrm.example.com
```

上述命令会将证书下载到您服务器上的目录。`/etc/letsencrypt/live/bookwyrm.example.com`

生成 **Diffie-Hellman 组**证书。

```
$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
```

对该过程进行试运行，以检查 SSL 续订是否正常工作。

\$ sudo certbot renew --dry-run

如果您没有看到错误，则一切就绪。您的证书将自动续订。

sudo certbot renew --dry-run 怎么定时运行？

要定时运行 `sudo certbot renew --dry-run` 以确保自动续订过程正常工作，你可以使用 `cron` 任务。以下是如何配置 `cron` 任务来定期运行此命令的步骤：

### 配置定时任务

1. **打开** `crontab` **编辑器**：

   bash

   ```
   sudo crontab -e
   ```

2. **添加定时任务**： 在 `crontab` 文件中添加一行以定期运行 `certbot renew --dry-run`。例如，每周一次在凌晨 2 点运行：

   plaintext

   ```
   0 2 * * 7 /usr/bin/certbot renew --dry-run >> /var/log/certbot-dry-run.log 2>&1
   ```

   这行命令的含义是：

   * `0 2 * * 7`：每周日的凌晨 2 点运行任务。

   * `/usr/bin/certbot renew --dry-run`：实际要运行的命令。

   * `>> /var/log/certbot-dry-run.log 2>&1`：将输出和错误日志重定向到 `/var/log/certbot-dry-run.log` 文件。

3. **保存并退出编辑器**： 在 nano 编辑器中，按 `Ctrl+O` 保存文件，然后按 `Ctrl+X` 退出。

### 示例 crontab 配置

以下是完整的 `crontab` 条目示例：

plaintext

```
0 2 * * 7 /usr/bin/certbot renew --dry-run >> /var/log/certbot-dry-run.log 2>&1
```

配置完成后，`cron` 将每周运行一次 `certbot renew --dry-run`，并将输出记录到日志文件中。这样你可以定期检查日志文件，确保证书续订过程正常。
