iRedMail 通过CertBot 获取Let’s encrypt证书

原文地址:https://cn.linux-console.net/?p=21331

具体操作根据自己的喜欢修改即可。

详细内容:
在我们之前的指南中,我们了解了如何安装和配置 iRedMail Server。 iRedMail 的默认安装会生成并安装用于邮件服务的自签名 SSL 证书 - POP3/IMAP/SMTP over TLS 以及用于 HTTPS 访问网络邮件服务。

使用自签名证书时,您经常会收到警告消息,指出正在使用的证书不受信任。为了避免这些恼人的消息,建议从 SSL 证书提供商购买 SSL 证书或获取免费的 Let’s Encrypt 证书。

在本指南中,我们将使用免费的 Let’s Encrypt SSL 证书来保护我们的 iRedMail 服务。为了能够获得 Let’s Encrypt SSL 证书,您的服务器应该有一个公共 IP 地址和指向该 IP 的 DNS 记录。

第1步:获取Let’s Encrypt证书
安装 certbot 工具,该工具将用于获取 Let’s Encrypt SSL 证书。

# Install certbot on Ubuntu /Debian
sudo apt update
sudo apt install certbot
# Install certbot on CentOS / Rocky
sudo yum -y install epel-release
sudo yum -y install certbot
安装 certbot-auto 工具后,保存 iRedMail 服务器的电子邮件地址和域名。

DOMAIN="mail.computingforgeeks.com"
EMAIL="email"
停止 Nginx 服务。
sudo systemctl stop nginx
为 iRedMail 邮件服务器获取免费的 Let’s Encrypt 证书。

sudo certbot certonly --standalone -d $DOMAIN --preferred-challenges http --agree-tos -n -m $EMAIL --keep-until-expiring
Let's Encrypt 的标准成功消息输出证书的路径。

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mail.computingforgeeks.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mail.computingforgeeks.com/privkey.pem
   Your cert will expire on 2023-06-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

步骤2:替换iRedMail自签名证书
重命名 iRedMail.crt自签名证书和私钥。

sudo mv /etc/pki/tls/certs/iRedMail.crt{,.bak}
sudo mv /etc/pki/tls/private/iRedMail.key{,.bak}

为 Let's Encrypt 证书和私钥创建符号链接。

sudo ln -sf /etc/letsencrypt/live/$DOMAIN/fullchain.pem /etc/pki/tls/certs/iRedMail.crt
sudo ln -sf  /etc/letsencrypt/live/$DOMAIN/privkey.pem /etc/pki/tls/private/iRedMail.key

重新启动 iRedMail 服务器以让服务使用新证书。

sudo reboot
步骤3:设置证书自动续订
创建一个 cron 作业来自动更新 Let’s Encrypt 证书:

$ sudo crontab -e
# Renew Let's Encrypt certs
15 3 * * * /usr/bin/certbot renew --pre-hook "systemctl stop nginx" --post-hook "systemctl start nginx"

添加 Let’s Encrypt SSL 证书后,邮件客户端应用程序(MUA,例如 Outlook、Thunderbird)不应警告您证书无效。与通过浏览器访问 Webmail 客户端相同。

如何将域和用户帐户添加到 iRedMail 邮件服务器

发表回复

登录... 后才能评论