在Debian上配置郵件服務器的SSL證書,通常涉及以下幾個步驟:
首先,確保你的Debian系統上安裝了Postfix和Certbot(用于獲取Let’s Encrypt證書)。
sudo apt update
sudo apt install postfix certbot
編輯Postfix的主配置文件 /etc/postfix/main.cf
,確保以下配置項正確設置:
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, $mydomain
mynetworks = 127.0.0.0/8 [::1]/128
home_mailbox = Maildir/
使用Certbot獲取Let’s Encrypt證書:
sudo certbot certonly --standalone -d mail.example.com -d example.com
按照提示完成證書的獲取和安裝。Certbot會自動創建證書文件并更新Postfix的配置文件。
Certbot會自動更新 /etc/letsencrypt/options-ssl-postfix.conf
文件。你需要將這個文件的內容合并到 /etc/postfix/main.cf
中。
sudo postmap /etc/letsencrypt/options-ssl-postfix.conf
然后編輯 /etc/postfix/main.cf
,添加以下內容:
smtpd_tls_security_level = may
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
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
應用配置更改并重啟Postfix服務:
sudo systemctl restart postfix
使用 openssl
命令驗證SSL配置是否正確:
openssl s_client -connect mail.example.com:465 -starttls smtp
如果一切正常,你應該會看到SSL握手成功的信息。
Certbot會自動續期證書,但你需要確保系統時間和時區設置正確。你也可以手動測試續期:
sudo certbot renew --dry-run
如果沒有問題,Certbot會自動續期證書。
確保你的防火墻允許SMTP(端口25)、SMTPS(端口465)和IMAP/POP3(端口143/993)流量。
sudo ufw allow 25/tcp
sudo ufw allow 465/tcp
sudo ufw allow 143/tcp
sudo ufw allow 993/tcp
完成以上步驟后,你的Debian郵件服務器應該已經成功配置了SSL證書。