Debian上PostFix的配置(一) - 配置成功 -转载

本文介绍如何在Debian系统中配置PostFix邮件服务器,包括安装、配置过程及常见问题解决办法,如saslauthd服务配置、SMTP认证等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Debian上PostFix的配置(一)    本文讲述完全使用Debian自带软件包架设使用系统用户,支持SMTP AUTH/POP3/IMAP的邮件系统,由于只是在单机上进行测试,所以本机安装了DNS服务器,对邮件域进行了解析,实际配置时DNS对邮件服务器非 常重要,为避免不必要的弯路,尽量在配置POSTFIX之前检查一下DNS配置是否正确。 

配置全过程如下: 

1. 为了让系统尽量使用最新的安装包,推荐在进行安装各软件前先apt-get update;apt-get upgrade一下。否则还有可能引起软件安装的兼容性问题,我遇到过几次在安装任何软件时均提示在安装过程中需先卸载e2fsprogs而安装失败的情 形,最好只好强行删除该软件再进行下一步,由于该操作会同时删除系统中其它重要软件,应尽量避免。 

2. 卸载Debian自带的exim4及相关软件包。 

3. 安装postfix及相关软件: 

apt-get install postfix postfix-doc libsasl2-2 sasl2-bin courier-imap courier-pop courier-authdaemon 

4. 开启saslauthd服务: 

默认地saslauthd是不开启的,在运行/etc/init.d/saslauthd start后没有任何反应,需要修改/etc/default/saslauthd文件如下:

START=yes 
MECHANISMS="shadow" 

然后重新输入命令/etc/init.d/saslauthd start可以看到saslauthd服务开启的提示。 

5. 测试saslauthd服务: 

运行ps ax|grep saslauthd,结果中如包含/usr/sbin/saslauthd -a shadow行则说明saslauthd服务正在运行,否则需要检查配置并启动saslauthd服务。 

sasl2-bin自带了一个测试saslauthd服务的命令testsaslauthd,如果系统中有用户test,密码为testpass,则运行testsaslauthd -u test -p testpass,如回应: 

0: OK "Success." 

则说明saslauthd服务工作正常。 

6. 配置smtp auth: 

修改/etc/postfix/main.cf文件如下: 

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) 
biff = no 

append_dot_mydomain = no 

myhostname = vd.vlinux.net 
alias_maps = hash:/etc/aliases 
alias_database = hash:/etc/aliases 
myorigin = /etc/mailname 
mydestination = $myorigin, localhost.localdomain, localhost 
relayhost = 
mynetworks = 127.0.0.0/8 
mailbox_size_limit = 0 
recipient_delimiter = + 
inet_interfaces = all 
home_mailbox = Maildir/ 
smtpd_sasl_auth_enable = yes 
smtpd_recipient_restrictions = 
permit_sasl_authenticated, 
reject_unknown_recipient_domain, 
reject_non_fqdn_recipient 
reject_non_fqdn_hostname, 
reject_non_fqdn_sender, 
reject_non_fqdn_recipient, 
reject_unauth_destination, 
reject_unauth_pipelining, 
reject_invalid_hostname, 
permit 

配置中的home_mailbox = Maildir/是指定postfix在进行邮件投递时使用与Qmail类似的Maildir方式,此方式每封邮件是一个独立的文件,比较易于管理,另外 IMAP默认也是在用户目录的Maildir中访问邮箱的,所以我选择了此种方式。在选Maildir方式时,mailbox_command选项应该置 空。 

其中vd.vlinux.net是本机的主机名,有两点比较重要: 

1)/etc/hosts文件必须有下面一行: 

192.168.5.2   vd.vlinux.net  vd 

2)/etc/mailname文件的内容必须是该域的域名。 

创建/etc/postfix/sasl/smtpd.conf文件如下: 

pwcheck_method: saslauthd 
saslauthd_path: /var/run/saslauthd/mux 
mech_list: PLAIN LOGIN 

很多资料都讲该文件应该在/usr/lib/sasl2目录下,我是经过许多次失败才忽然发现应该放在这里的,可能是Debian的不同吧。现在重启 postfix:/etc/init.d/postfix restart,通过telnet 25端口检查smtp auth是否已经开始工作。 

vd:~# telnet localhost 25 
Trying 127.0.0.1... 
Connected to localhost.localdomain. 
Escape character is '^]'. 
220 vd.vlinux.net ESMTP Postfix (Debian/GNU) 
ehlo localhost 
250-vd.vlinux.net 
250-PIPELINING 
250-SIZE 10240000 
250-VRFY 
250-ETRN 
250-AUTH LOGIN PLAIN 
250 8BITMIME ] 

出现250-AUTH ……一行就说明smtp auth功能已经添加。 

7. 看起来一切都工作正常了,试一下发信: 

vd:~# telnet localhost 25 
Trying 127.0.0.1... 
Connected to localhost.localdomain. 
Escape character is '^]'. 
220 vd.vlinux.net ESMTP Postfix (Debian/GNU) 
ehlo localhost 
250-vd.vlinux.net 
250-PIPELINING 
250-SIZE 10240000 
250-VRFY 
250-ETRN 
250-AUTH LOGIN PLAIN 
250 8BITMIME 
auth login 
334 VXNlcm5hbWU6 
dGVzdA== //用户名test的的Base64编码 
334 UGFzc3dvcmQ6 
dGVzdHBhc3M= //密码testpass的Base64编码 
535 Error: authentication failed 

Base64编码可以perl或任何一种脚本语言获得: 

perl: 

perl -MMIME::Base64 -e 'print encode_base64("user")' 

PHP: 

php -r 'echo base64_encode("user")."\n";' 

OPENSSL: 

echo -n "user" | openssl base64 -a 

提示认证失败,查看/var/log/mail.log文件发现有以下信息: 

Feb 26 23:39:47 vd postfix/smtpd[2323]: connect from localhost.localdomain[127.0.0.1] 
Feb 26 23:39:57 vd postfix/smtpd[2323]: warning: SASL authentication failure: cannot connect to saslauthd server: No such file or directory 
Feb 26 23:39:57 vd postfix/smtpd[2323]: warning: localhost.localdomain[127.0.0.1]: SASL login authentication failed 

事实上,根据smtpd.conf文件/var/run/saslauthd/mux文件是存在的,留作疑问。 

经试验,修改/etc/postfix/master.cf中smtp服务行如下,以取消chroot方式运行: 

smtp   inet n    -    n    -    -    smtpd 

重启postfix,重复以上步骤,发现认证仍然失败,但日志中信息提示: 

Feb 26 23:47:23 vd postfix/smtpd[2405]: warning: SASL authentication failure: cannot connect to saslauthd server: Permission denied 

修改/var/run/saslauthd目录的权限使postfix用户可以访问,再试试验,发现认证已可通过。但是当saslauthd服务器重启时出现如下提示: 

Starting SASL Authentication Daemon: ‘/var/run/saslauthd’ 的权限模式已更改为 0710 (rwx--x---) 

此时smtp认证又失败了,原因是saslauthd服务在启动时要先执行dpkg-statoverride命令将一些指定目录的权限进行恢复,可能是为了某种安全目的,有两种方法可以解决此问题,个人推荐第2种方法: 

1)将文件/var/lib/dpkg/statoverride中“root sasl 710 /var/run/saslauthd”一行删除,或执行dpkg-statoverride --remove /var/run/saslauthd完成相同的操作。 

2)将postfix用户加入sasl组。 

至此,配置工作完全结束了,有些系统上用户目录的Maildir目录要用特定的命令手工创建,Debian下在收到第一封邮件时就会自动创建了。 

转载于:https://my.oschina.net/jack230230/blog/121794

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值