在 debian 11 里,为 postfix 配置 saslauthd pam 验证 用户名和密码

目标:在 debian 11 系统里,安装 postfix ,且配置 saslauthd pam 验证用户登录。

步骤:

  1. hostnamectl set-hostname my.example.com # 设置主机名
  2. 127.0.0.1 my.example.com # 在 /etc/hosts 里添加一行,保存主机名配置
  3. apt install postfix sasl2-bin libsasl2-modules # 安装 postfix , sasl 框架
    在弹出的 postfix 配置框时,选择 Internet Site ,表示 机子将直接发送和收取邮件;System mail name 会自动显示在第一步时设置的,保持不变就行
  4. 因为 postfix 默认运行在 chroot 环境中,所以要创建一个 saslauthd 跟它搭配
    4.1 创建配置文件:/etc/postfix/sasl/smtpd.conf 内容如下:

    pwcheck_method: saslauthd
    mech_list: CRAM-MD5 DIGEST-MD5 LOGIN PLAIN

    4.2 cp /etc/default/saslauthd /etc/default/saslauthd-postfix 复制默认的配置文件内容,且修改成如下内容:

    START=yes
    DESC="SASL Authentication for postfix"
    NAME="saslauthd-postf"
    MECHANISMS="pam"
    MECH_OPTIONS=""
    THREADS=5
    OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"

    4.3 设置目录的权限:dpkg-statoverride --add root postfix 710 /var/spool/postfix/var/run/saslauthd

  5. 修改 /etc/postfix/main.cf 文件内容,确保有以下 sals 相关的内容:

    smtpd_sasl_auth_enable = yes
    smtpd_sasl_security_options = noanonymous
    smtpd_sasl_local_domain = $myhostname
    broken_sasl_auth_clients = yes
  6. systemctl restart postfix # 重启 postfix 服务
  7. 顺利的话,就可以使用普通用户发出邮件的,如:
    swaks --to he@example.com --from wuhan@example.com --server localhost --auth LOGIN --auth-user wuhan --auth-password yourpassword

参考:https://wiki.debian.org/PostfixAndSASL

标签: debian, postfix, saslauthd

添加新评论