温馨提示×

Ubuntu邮件服务器如何认证

小樊
46
2026-07-31 12:33:52
栏目: 云计算

Ubuntu 邮件服务器中,“认证”通常指 SMTP 发信认证(SMTP AUTH),以及可选的 IMAP/POP3 收信认证。下面按常见场景系统性说明。


一、最常见的认证方式(SMTP AUTH)

用途:防止邮件服务器被当成“开放中继(Open Relay)”被滥用。

✅ 推荐方案

Postfix + Dovecot SASL + 系统用户 / 虚拟用户


二、基础环境(示例)

  • Ubuntu 20.04 / 22.04
  • Postfix(MTA)
  • Dovecot(IMAP/POP3 + SASL)
  • 域名:mail.example.com

三、SMTP 认证配置(核心)

1️⃣ 安装必要软件

sudo apt update
sudo apt install postfix dovecot-core dovecot-imapd dovecot-pop3d

2️⃣ 配置 Dovecot(提供 SASL 认证)

编辑:

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

添加或修改:

service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix
  }
}

编辑:

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

启用明文认证(在 STARTTLS 下安全):

disable_plaintext_auth = no
auth_mechanisms = plain login

✅ 推荐:使用系统用户认证

# 使用 PAM(系统用户)
# 默认已启用

3️⃣ 配置 Postfix 使用 Dovecot 认证

编辑:

sudo nano /etc/postfix/main.cf

添加:

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous

smtpd_recipient_restrictions =
  permit_sasl_authenticated,
  permit_mynetworks,
  reject_unauth_destination

4️⃣ 重启服务

sudo systemctl restart dovecot
sudo systemctl restart postfix

四、测试 SMTP 认证

使用 telnet(测试)

telnet mail.example.com 25
EHLO test.com
STARTTLS
AUTH LOGIN

或使用 swaks

sudo apt install swaks
swaks --to user@example.com \
      --from user@example.com \
      --server mail.example.com \
      --auth \
      --port 587

五、IMAP / POP3 认证(收信)

Dovecot 默认已支持:

  • IMAP:143(STARTTLS)
  • IMAPS:993(SSL)
  • POP3:110
  • POP3S:995

认证方式:

  • 用户名:完整邮箱(如 user@example.com
  • 密码:系统用户或虚拟用户密码

六、虚拟用户认证(进阶)

如果你不想用 Linux 系统用户,可用:

  • MySQL / PostgreSQL
  • Maildir 存储
  • PostfixAdmin 管理

常见组合:

Postfix + Dovecot + MySQL + PostfixAdmin

七、常见认证失败原因

问题 原因
535 Authentication failed 用户名/密码错误
no mechanism found auth_mechanisms 未启用
permission denied unix socket 权限问题
中继被拒绝 未启用 permit_sasl_authenticated

八、安全建议(非常重要)

✅ 启用 TLS:

  • SMTP:587 + STARTTLS
  • IMAP:993
  • POP3:995

✅ 禁用开放中继
✅ 使用强密码
✅ 配合 Fail2ban 防暴力破解


九、我可以继续帮你

你可以告诉我:

  1. 用的是 Postfix / Exim / Sendmail
  2. 系统用户还是虚拟用户
  3. 是否已有 SSL 证书(Let’s Encrypt)
  4. 想做 企业邮箱 / 个人邮箱 / 内网邮件

我可以直接给你 完整可复制配置方案

0