1 前言
一个问题,一篇文章,一出故事。
接到老板的需求smtp服务器处理兼容IP地址认证,还要启用账号密码的认证,于是根据需求整理当前章节。
本章的PostFix作为smtp的认证来源于Dovecot,Dovecot虽然用于实现POP协议,详细见如下章节:
但是,本章将调用他作为PostFix的认证来源。
2 最佳实践
2.1 配置PostFix环境
2.1.1 PostFix的基础配置
另外,由于上面的章节有按照以下章节修改过邮件队列目录的位置,因此后面的Dovecot路径需要根据实际调整。详细见如下章节:
2.1.2 加入PostFix集成Dovecot的认证配置
基于以上环境,我们使用如下命令编辑配置文件,
vim /etc/postfix/main.cf
修改或加入如下配置,
smtpd_sasl_auth_enable = yes smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
配置修改后,我们需要执行如下命令重启服务并使配置生效,
systemctl restart postfix systemctl status postfix
2.1.3 将密码认证和IP认证修改为并行的认证
vim /etc/postfix/main.cf
修改如下配置,
#smtpd_client_restrictions = check_client_access hash:/etc/postfix/access, reject smtpd_client_restrictions = permit_sasl_authenticated, check_client_access hash:/etc/postfix/access, reject
新的配置输入用户名和密码后不检查IP地址,直接放行。配置修改后,我们需要执行如下命令重启服务并使配置生效,
systemctl restart postfix systemctl status postfix
2.2 安装配置dovecot
2.2.1 安装软件包
In mail0[1,2],
yum install -y dovecot
2.2.2 启动与设置自启动并获取状态
In mail0[1,2],
systemctl start dovecot.service systemctl enable dovecot.service systemctl status dovecot.service
服务启动后,建议你使用如下命令查看端口倾听状态,
netstat -antp | grep "dovecot"
可见如下显示,
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 31210/dovecot tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 31210/dovecot tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 31210/dovecot tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 31210/dovecot tcp6 0 0 :::143 :::* LISTEN 31210/dovecot tcp6 0 0 :::993 :::* LISTEN 31210/dovecot tcp6 0 0 :::995 :::* LISTEN 31210/dovecot tcp6 0 0 :::110 :::* LISTEN 31210/dovecot
2.2.3 配置认证方式
In mail0[1,2],
grep '!include auth-' /etc/dovecot/conf.d/10-auth.conf
可通过如下命令确认开启的认证方式,
#!include auth-deny.conf.ext #!include auth-master.conf.ext !include auth-system.conf.ext #!include auth-sql.conf.ext #!include auth-ldap.conf.ext #!include auth-passwdfile.conf.ext #!include auth-checkpassword.conf.ext #!include auth-vpopmail.conf.ext #!include auth-static.conf.ext
需要注意的是,
– 以上非注解配置为“auth-system.conf.ext”,即引用系统账号作为认证凭据
– Linux默认root用户不允许登录,你需要创建普通用户作为邮件账号
并且你还需要修改或加入如下配置,
auth_mechanisms = plain login
2.2.4 配置Postfix套接字(Socket)文件
In mail0[1,2],
vim /etc/dovecot/conf.d/10-master.conf
修改或加入如下配置,
unix_listener /data/postfix/queue/private/auth {
mode = 0666
}
2.3 测试smtp认证
2.3.1 创建认证用户
useradd will echo willpassword | passwd --stdin will
有时候安全起见,我们会使用如下命令拿掉用户的系统登录Shell(可选),
usermod -s /sbin/nologin will
当然,根据具体的需求,也可以重新加上系统登录Shell(可选),
usermod -s /bin/bash will
2.3.2 创建认证用户
参阅文档
=================
Dovecot官方主页
————-
https://www.dovecot.org/
Dovecot使用文档
————————
https://doc.dovecot.org/
没有评论