温馨提示×

Debian OpenSSL证书如何续期

小樊
44
2025-12-19 06:36:33
栏目: 云计算

Debian 上 OpenSSL 证书续期指南

一、先判断证书类型

  • 使用 Let’s Encrypt 等 ACME 颁发的证书:推荐用 Certbot 自动续期,证书默认有效期 90 天,Certbot 通常会自动创建定时任务或 systemd 定时器完成续期。
  • 使用 自签证书(自建 CA 或本地测试):没有自动 CA,需重新签发并替换,再重载服务。
  • 其他 CA(如商用或企业内 CA):按该 CA 流程重新签发,然后更新服务端证书路径并重启相关服务。

二、Let’s Encrypt 证书续期(Certbot)

  • Apache
    • 安装与获取:sudo apt update && sudo apt install certbot python3-certbot-apache;获取证书:sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
    • 验证与自动续期:执行 sudo certbot renew --dry-run 测试;Certbot 默认已配置自动续期(cron 或 systemd timer)。
    • 重载服务:sudo systemctl reload apache2。
  • Nginx
    • 安装与获取:sudo apt install certbot python3-certbot-nginx;获取证书:sudo certbot --nginx -d yourdomain.com
    • 可选优化:启用 OCSP Stapling(在续期/申请时选择启用),验证命令:openssl s_client -connect yourdomain.com:443 -tls1_2 -tlsextdebug,输出中能看到 OCSP response 即生效。
    • 重载服务:sudo systemctl reload nginx。

三、自签或内部 CA 证书的续期

  • 查看有效期:openssl x509 -in server.crt -noout -dates。
  • 重新签发(示例,RSA 2048,有效期 365 天):
    • 生成私钥:openssl genpkey -algorithm rsa -out server.key -aes256
    • 生成 CSR:openssl req -new -key server.key -out server.csr
    • 签发证书:openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
  • 部署与重载:将新的 server.crtserver.key 放到服务配置指定路径,然后重载服务(如 sudo systemctl reload nginx 或 apache2)。
  • 清理:确认新证书生效后,备份并删除旧证书文件。

四、其他服务与运维要点

  • 邮件服务(Postfix 示例)
    • 获取证书:sudo certbot certonly --standalone -d mail.example.com
    • 配置:在 /etc/postfix/main.cf 中设置
      • smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
      • smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
      • smtpd_use_tls = yes
    • 应用:sudo postmap /etc/letsencrypt/options-ssl-postfix.conf && sudo systemctl restart postfix。
  • 通用运维
    • 续期后务必重载服务,使新证书生效。
    • 定期核查证书到期时间:openssl x509 -in server.crt -noout -dates。
    • 确保系统 时间与时区 正确,避免续期失败或证书异常。

0