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.com
mydomain = studying.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks_style = subnet
mynetworks = 192.168.100.0/24, 127.0.0.0/8
home_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: saslauthd
mech_list: plain login [root@localhost ~]# vim /etc/sysconfig/saslauthd
# 修改saslauthd的配置文件
MECH=shadow [root@localhost ~]# systemctl enable --now saslauthd
# 开启并开机自启sasl验证服务
testsaslauthd -u testuser1 -p abc.123
0: OK "Success."
# 测试sasl验证是否正常

接下来为Postfix配置别名。

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

测试环境

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

# 如下命令使用命令行进行测试
220 mail.studying.com ESMTP Postfix
helo testuser1@studying.com
250 mail.studying.com
auth login
334 VXNlcm5hbWU6
dGVzdHVzZXIx
334 UGFzc3dvcmQ6
YWJjLjEyMw==
235 2.7.0 Authentication successful
mail from:<testuser1@studying.com>
250 2.1.0 Ok
rcpt to:<testuser1@studying.com>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
This is a test mail
.
250 2.0.0 Ok: queued as A895C2088490
mail from:<testuser1@studying.com>
250 2.1.0 Ok
rcpt to:<testuser@studying.com>
250 2.1.5 Ok
data
354 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.com
Delivered-To: testuser1@studying.com
Received: 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.com
Delivered-To: testuser@studying.com
Received: 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文件来确定验证结果。

最新文章

  1. 批量执行SQL语句,进行删除,插入或者更改。
  2. c# ref 的作用
  3. Windows Azure Website类别、限制条件
  4. volley+NetworkImageView实现列表界面的列表项中的左侧图标展现之【实现已经加载的列表项的图标上翻的时候不重新加载】
  5. mac下安装git,并将本地的项目上传到github
  6. Java一点输入输出技巧
  7. Asp.Net Core&amp;钉钉开发系列
  8. openJDK知识整理及概念
  9. vue v-for动画bug
  10. codeblocks修改字体颜色-背景颜色
  11. GALV_maptravel研究分析(2)
  12. oracle:10g下载地址(转载)
  13. 基于vue2.0实现仿百度前端分页效果(一)
  14. SQL Server 2012使用Offset/Fetch Next实现分页
  15. asp.net mvc流程图4.6以前
  16. Go语言学习之4 递归&amp;闭包&amp;数组切片&amp;map&amp;锁
  17. python turtle 例子 海归绘图
  18. [转]仿91助手的PC与android手机通讯
  19. centos6.9+lnmp1.5环境部署swoole记录
  20. Codeforces Round #239 (Div. 1) 二项式差分

热门文章

  1. mac mini 装UBUNTU后没有WIFI解决办法
  2. 覆盖率检查工具:JaCoCo 食用指南
  3. 《The Tail At Scale》论文详解
  4. JQuery select与radio的取值与赋值
  5. Java中将对象或者集合对象转换成json字符串
  6. SpringBoot配置多环境下的properties配置文件
  7. 官宣!微软发布 VS Code Server!
  8. Java对接拼多多开放平台API(加密上云等全流程)
  9. CMU15445 (Fall 2019) 之 Project#4 - Logging &amp; Recovery 详解
  10. macOS Monterey 12.5 (21G72) 正式版 ISO、IPSW、PKG 下载