温馨提示×

debian邮件服务器怎么 ssl 加密

小樊
43
2026-09-11 12:43:01
栏目: 云计算

在 Debian 上搭建支持 SSL/TLS 加密的邮件服务器,通常包含三个部分:

  1. SMTP(发信) → 用 Postfix + TLS
  2. IMAP/POP3(收信) → 用 Dovecot + TLS
  3. 证书 → 使用 Let’s Encrypt(推荐)或自签证书

下面给你一套最常见、可用的实战方案(Debian 11/12 通用)。


一、准备环境

sudo apt update
sudo apt install postfix dovecot-core dovecot-imapd \
     dovecot-pop3d certbot -y

二、申请 SSL 证书(Let’s Encrypt)

假设你的邮件域名是:

mail.example.com

1. 申请证书

sudo certbot certonly --standalone -d mail.example.com

证书位置:

/etc/letsencrypt/live/mail.example.com/
├── fullchain.pem
└── privkey.pem

三、配置 Postfix(SMTP + SSL)

1. 编辑主配置

sudo nano /etc/postfix/main.cf

添加或修改:

myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain

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_tls_security_level = may
smtpd_tls_protocols = !SSLv2, !SSLv3, TLSv1.2, TLSv1.3

smtp_tls_security_level = may
smtp_tls_protocols = !SSLv2, !SSLv3, TLSv1.2, TLSv1.3

smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache

2. 启用 465 / 587 端口

编辑:

sudo nano /etc/postfix/master.cf

启用:

submission inet n - y - - smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes

smtps inet n - y - - smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes

3. 重启 Postfix

sudo systemctl restart postfix

四、配置 Dovecot(IMAP/POP3 + SSL)

1. 配置 SSL

sudo nano /etc/dovecot/conf.d/10-ssl.conf
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
ssl_min_protocol = TLSv1.2

2. 启用 IMAPS / POP3S

sudo nano /etc/dovecot/conf.d/10-master.conf

确保:

service imap-login {
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}

service pop3-login {
  inet_listener pop3s {
    port = 995
    ssl = yes
  }
}

3. 重启 Dovecot

sudo systemctl restart dovecot

五、防火墙放行端口

sudo ufw allow 25,465,587,993,995/tcp

六、自动续期证书(重要)

sudo crontab -e

添加:

0 3 * * * certbot renew --quiet && systemctl reload postfix dovecot

七、验证 SSL 是否生效

openssl s_client -connect mail.example.com:993
openssl s_client -connect mail.example.com:465

看到 Verify return code: 0 (ok) 就成功了。


八、常见注意点

✅ DNS 要配置:

  • A 记录 → mail.example.com
  • MX 记录 → example.com
  • PTR 反向解析(非常重要)

✅ 邮件客户端配置:

  • SMTP:465 / 587(SSL/TLS)
  • IMAP:993(SSL/TLS)
  • POP3:995(SSL/TLS)

如果你愿意,我可以:

  • 帮你一步步按你的域名配置
  • 给你一套 Postfix + Dovecot 最小化可用配置
  • 或讲 自签证书 vs Let’s Encrypt 区别

你现在是新装还是已有邮件服务器要加 SSL

0