Postfix别名邮件与SASL验证

博客 动态
0 156
羽尘
羽尘 2022-08-28 14:03:45
悬赏:0 积分 收藏

Postfix别名邮件与SASL验证

Postfix别名邮件与SASL验证

环境简介

系统:

  • CentOS 8.3.2011

软件包:

  • postfix-2:3.3.1-12.el8.x86_64
  • cyrus-sasl-2.1.27-5.el8.x86_64
  • cyrus-sasl-plain-2.1.27-5.el8.x86_64

软件源:

  • CentOS-8.3.2011-x86_64-dvd1.iso 自带软件源

操作步骤

如下为Postfix配置SASL验证。

[root@localhost ~]# yum install -y vim postfix cyrus-sasl net-tools# 最小化安装系统 安装所需软件包 Yum配置略过[root@localhost ~]# vim /etc/postfix/master.cf# 修改Postfix配置文件,将以下项的注释删除 开启smtpd功能,修改完成后保存退出smtpd     pass  -       -       n       -       -       smtpd[root@localhost ~]# vim /etc/postfix/main.cf# 修改Postfix配置文件,完成初始化配置及开启SASL验证功能。如下项最好根据实际情况修改。myhostname = mail.studying.commydomain = studying.commyorigin = $mydomaininet_interfaces = allmydestination = $myhostname, localhost.$mydomain, localhost, $mydomainmynetworks_style = subnetmynetworks = 192.168.100.0/24, 127.0.0.0/8home_mailbox = Maildir/smtpd_sasl_auth_enable = yes[root@localhost ~]# systemctl enable --now postfix# 启动Postfix并设置Postfix开机自启[root@localhost ~]# firewall-cmd --add-service=smtp --per [root@localhost ~]# firewall-cmd --reload# 设置防火墙允许访问smtp服务

配置SASL2

[root@localhost ~]# setsebool -P allow_saslauthd_read_shadow 1# 设置SELinux允许saslauthd访问/etc/shadow文件[root@localhost ~]# cat /etc/sasl2/smtpd.conf# 文件默认内容应该就如下所示pwcheck_method: saslauthdmech_list: plain login[root@localhost ~]# vim /etc/sysconfig/saslauthd# 修改saslauthd的配置文件MECH=shadow[root@localhost ~]# systemctl enable --now saslauthd# 开启并开机自启sasl验证服务testsaslauthd -u testuser1 -p abc.1230: OK "Success."# 测试sasl验证是否正常

接下来为Postfix配置别名。

[root@localhost ~]# postconf -p | grep alias_maps alias_maps = hash:/etc/aliases# 检查别名文件,并在文件中添加如下内容[root@localhost ~]# vim /etc/aliasestestuser:       testuser1, testuser2, testuser3[root@localhost ~]# newaliases# 使用如上命令重新生成别名数据库[root@localhost ~]# systemctl restart postfix# 重启Postfix服务

测试环境

接下来使用telnet命令行进行测试

# 如下命令使用命令行进行测试220 mail.studying.com ESMTP Postfixhelo testuser1@studying.com250 mail.studying.comauth login334 VXNlcm5hbWU6dGVzdHVzZXIx334 UGFzc3dvcmQ6YWJjLjEyMw==235 2.7.0 Authentication successfulmail from:<testuser1@studying.com>250 2.1.0 Okrcpt to:<testuser1@studying.com>250 2.1.5 Okdata354 End data with <CR><LF>.<CR><LF>This is a test mail.250 2.0.0 Ok: queued as A895C2088490mail from:<testuser1@studying.com>250 2.1.0 Okrcpt to:<testuser@studying.com>250 2.1.5 Okdata354 End data with <CR><LF>.<CR><LF>this is a testmail two!.250 2.0.0 Ok: queued as 9AA66208849A# 邮件发送完毕后通过在用户家目录查阅邮件,从而验证邮件发送的成功[root@localhost new]# pwd/home/testuser1/Maildir/new[root@localhost new]# cat 1661604766.Vfd00I20e7d75M249613.localhost.localdomain Return-Path: <testuser1@studying.com>X-Original-To: testuser1@studying.comDelivered-To: testuser1@studying.comReceived: from testuser1?studying.com (unknown [192.168.100.1])        by mail.studying.com (Postfix) with SMTP id A895C2088490        for <testuser1@studying.com>; Sat, 27 Aug 2022 20:52:27 +0800 (CST)This is a test mail[root@localhost new]# pwd/home/testuser2/Maildir/new[root@localhost new]# cat 1661618666.Vfd00I20e7d7dM301979.localhost.localdomain Return-Path: <testuser1@studying.com>X-Original-To: testuser@studying.comDelivered-To: testuser@studying.comReceived: from testuser1?studying.com (unknown [192.168.100.1])        by mail.studying.com (Postfix) with SMTP id 9AA66208849A        for <testuser@studying.com>; Sun, 28 Aug 2022 00:44:10 +0800 (CST)this is a testmail two!

SASL杂谈

SASL(Simple Authentication and Security Layer)简单身份验证和安全层,是由IETF开发的协议,用于提供可插入或可扩展的身份验证框架,具体的定义参见RFC4422。这个协议通常用于电子邮件相关的协议,例如SMTP、IMAP、POP还有XMPP、LDAP等,在上述与Postfix相结合的实例中,我们只是使用到了它的简单身份验证,并没有用到安全层。

关于安全层的内容暂且按下不谈,先聊聊SASL在整个身份验证架构中的位置。首先,SASL是处于服务协议(例如SMTP、IMAP)与验证机制(Plain、GSSAPI)之间的机制,那么一旦配置了SASL的认证,它往往能够隐藏验证机制,但不会隐藏验证机制的细节,例如不同的机制需要不同的信息进行验证,例如一些机制需要使用Kerberos的票据、证书等。

在SASL的验证架构中,涉及到的有两种身份:

  • 与认证凭据相关的身份(称为身份验证身份)
  • 充当的身份(授权身份)

在服务器进行验证的过程中,需要建立身份验证的身份与授权的身份的一一映射,也就是验证账户到实际账户的映射(而这个形式则是由应用程序所规定的)。

那么我们回到上述的POSTFIX+SASL实例中,POSTFIX实质是通过Unix进程间通信来传递身份凭据进行验证。并且采用的验证方法是访问/etc/shadow文件来确定验证结果。

posted @ 2022-08-28 13:18 ZywOo 阅读(0) 评论(0) 编辑 收藏 举报
回帖
    羽尘

    羽尘 (王者 段位)

    2335 积分 (2)粉丝 (11)源码

     

    温馨提示

    亦奇源码

    最新会员