在Debian 4.0 rc3上安装postfix+sasl验证及防垃圾SPAM机制

作者:何祖彬[RobinHe] Mail:zubin.he@gmail.com
始于2008年8月4日 PM
版本号:Debian-Postfix-SASL-SPAM-V1.0-20080804, 2008年8月4日首版

转载请注明出处,本文也是采用两篇网友的大部分内容,因此转载时,请也将下面“参考文章”的出处也一并加入!谢谢!
本文中难免有不足、遗漏、错别字和句子不通之处,如发现、或者有更新改变之处,请与我联系以及时修正和完善!

系统信息:
OS : Debian 4.0 rc3

使用说明:
绿色加粗字体的绝大部分是输入的命令和系统输出显示的结果。

参考文章:
POSTFIX+SASL:
http://www.debian.org.tw/index.php/Postfix-SASL

http://community.itbbs.cn/showthread.php?t=7395



让 Postfix 支持 Cyrus-SASL© V2 认证


第一步,安装所需套件并进行相关的配置:

#apt-get install openssh-blacklist postfix-tls sasl2-bin libsasl2-modules spamassassin popa3d

修改/etc/default/saslauthd文件,让START=yes,即,启动SASL认证:
#vi /etc/default/saslauthd

# This needs to be uncommented before saslauthd will be run automatically
START=yes

修改 /etc/postfix/sasl/smtpd.conf,设定 PostFix 使用 Saslauthd
#mkdir -p /etc/postfix/sasl
#echo "pwcheck_method: saslauthd" > /etc/postfix/sasl/smtpd.conf

再编辑这个文件:/etc/postfix/sasl/smtpd.conf加入下面这一句:
mech_list: plain login 将postfix 加入 sasl 群组中
#addgroup postfix sasl

修改 /etc/postfix/main.cf,使其使用 SMTP AUTH 及 SASL Authenticate 以及 加入spam防垃圾邮件机制

#vi /etc/postfix/main.cf
# Enable SASL Auth

# 設定 Postfix 使用 SASL 認証。
smtpd_sasl_auth_enable = yes

# 設定 SASL 支援非標準 E-mail Client 的認証動作。
broken_sasl_auth_clients = yes

# 不使用 ANONYMOUS 這個認証。
smtpd_sasl_security_options = noanonymous

# 設定 SASL 的認証方法
# permit_sasl_authenticated → 如果用戶端可通過 SASL 認証則可 Relay Mail。
# permit_mynetworks → 如果用戶端的位址為 $mynetworks 則可 Relay Mail。
# check_relay_domains
# reject_unauth_destination
smtpd_client_restrictions =

smtpd_helo_required = yes
smtpd_helo_restrictions =

smtpd_sender_restrictions =

smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination,
    reject_invalid_hostname,
    check_sender_access  hash:/etc/postfix/sender_access,
    reject_unauth_pipelining,
    reject_non_fqdn_sender,
    reject_unknown_sender_domain,
    reject_unverified_sender,
    reject_multi_recipient_bounce,
    reject_non_fqdn_recipient,
    reject_unknown_recipient_domain,
    reject_rbl_client      cbl.abuseat.org,
    reject_rbl_client      dul.dnsbl.sorbs.net,
    reject_rbl_client      zen.spamhaus.org,
    reject_rbl_client      list.dsbl.org,
    reject_rbl_client      opm.blitzed.org,
    reject_rhsbl_sender    dsn.rfc-ignorant.org,
    permit


保存退出。

同时重启SASL:
#/etc/init.d/saslauthd restart

验证SASL是否正常工作:
#testsaslauthd -u username -p password

重启postfix:
#/etc/init.d/postfix restart

第二步,修正调整Debian中Postfix+SASL的一些配置[谢谢HENRY的帮忙解决以下的问题,以下是我的总结]:

因为Debian的postfix套件预设用chroot安装在/var/spool/postfix。因此, /etc/sasldb2要搬到/var/spool/postfix/etc/sasldb2,否则在非本地IP用SASL验证时会出现以下错误:
Jun 24 11:12:36 www last message repeated 2 times
Jun 24 11:12:36 www postfix/smtpd[15023]: warning: SASL authentication failure: no secret in database
Jun 24 11:12:36 www postfix/smtpd[15023]: warning: unknown[222.222.222.222: SASL NTLM authentication failed: authentication failure
Jun 24 11:12:36 www postfix/smtpd[15023]: warning: SASL authentication problem: unable to open Berkeley db /etc/sasldb2: No such file or directory
Jun 24 11:12:36 www last message repeated 5 times
Jun 24 11:12:36 www postfix/smtpd[15023]: warning: SASL authentication failure: Password verification failed
Jun 24 11:12:36 www postfix/smtpd[15023]: warning: unknown[222.222.222.222]: SASL PLAIN authentication failed: authentication failure

因为它找不到sasldb2这件相对于/var/spool/postfix下的/etc/sasldb2文件,log中的/etc/sasldb2其实 就是/var/spool/postfix/etc/sasldb2,现在这个目录下找不到这个文件,因此会提示:No such file or directory

因此:
#cp /etc/sasldb2 /var/spool/postfix/etc/.
同时在/etc/group中加入相应的组:
mail:x:8:postfix
sasl:x:45:postfix

但是在Debian/Ubuntu环境下,因为chroot的关系,所以还要将saslauthd的PIDFILE目录修改为 /var/spool/postfix/var/run/saslauthd,所以请先建立这个目录:
#mkdir /var/spool/postfix/var
#mkdir /var/spool/postfix/var/run
#mkdir /var/spool/postfix/var/run/saslauthd

然后修改/etc/default/saslauthd文件:
START=yes
MECHANISMS="pam"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"

重启saslauthd:

#/etc/init.d/saslauthd restart

确认一下saslauthd.pid不在/var/run下,而是在新的目录 /var/spool/postfix/var/run/saslauthd下面,

然后在利用远程电脑发一送需要SMTP验证的MAIL,看一下是事正常,同时检查/var/log/mail.log


第三步,配置spamassassin防垃圾邮件系统的启动文件:

编辑/etc/default/spamassassin文件,
#vi /etc/default/spamassassin
将:
ENABLE=0改为1,即ENABLE=1 说明系统为启动状态!

完成...

接下去做SSL收发MAIL的配置,期待中...









-------------------------------------------------------------------------------------
参考资料:
http://www.debian.org.tw/index.php/Postfix-SASL

Postfix-SASL

出自DebianWiki

目錄

[隱藏]
<script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "顯示"; var tocHideText = "隱藏"; showTocToggle(); } </script>

[編輯] 所需套件

postfix-tls sasl2-bin libsasl2-modules

[編輯] Mail Relay 簡介

所謂的 Mail Relay,指的就是 Mail Server 會不會替使用者將信轉寄到外部去。

比如說,我將信寄給 tetralet@pchome.com.tw,如果 tetralet@pchome.com.tw 這個信箱並不是位於本機上,那麼這封信將會轉給PCHome 的 Mail Server,而這個將郵件轉寄的動作就是 Mail Relay。

Open Relay 就是不設限地完全開放 Mail Relay 的功能,它會替所有的人進行郵件轉寄。

架設 Mail Server 的第一件事,就是防止不速之客利用您的 Mail Server 來亂發郵件,也就是關掉 Open Relay 這個功能。(基本上,幾乎所有的 Mail Server 預設上都已把 Open Relay 給關掉了) 取而代之的,是使用 SMTP 認証 (SMTP AUTH) 來驗証使用者可否進行 Mail Relay。

在這裡所要介紹的,是如何使用 Cyrus-SASL© V2 來實作 SMTP 認証的功能。 其中的 SASL (Simple Authentication and Security Layer) 就是用來提供符合 RFC 2222 標準的各種認証機制的 Daemon。

[編輯] 讓 Postfix 支援 Cyrus-SASL© V2 認証:(Debian Sarge)

  • 修改 /etc/default/saslauthd,設定 START=yes
# This needs to be uncommented before saslauthd will be run automatically
START=yes

# You must specify the authentication mechanisms you wish to use.
# This defaults to "pam" for PAM support, but may also include
# "shadow" or "sasldb", like this:
# MECHANISMS="pam shadow"

MECHANISMS="pam"
  • 修改 /etc/postfix/sasl/smtpd.conf,設定 PostFix 使用 Saslauthd
mkdir -p /etc/postfix/sasl
echo "pwcheck_method: saslauthd" > /etc/postfix/sasl/smtpd.conf
  • 將 postfix 加入 sasl 群組中
addgroup postfix sasl
  • 修改 /etc/postfix/main.cf,使其使用 SMTP AUTH 及 SASL Authenticate
(上略)

# Enable SASL Auth

# 設定 Postfix 使用 SASL 認証。
smtpd_sasl_auth_enable = yes

# 設定 SASL 支援非標準 E-mail Client 的認証動作。
broken_sasl_auth_clients = yes

# 不使用 ANONYMOUS 這個認証。
smtpd_sasl_security_options = noanonymous

# 設定 SASL 的認証方法
# permit_sasl_authenticated → 如果用戶端可通過 SASL 認証則可 Relay Mail。
# permit_mynetworks → 如果用戶端的位址為 $mynetworks 則可 Relay Mail。
# check_relay_domains
# reject_unauth_destination
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, check_relay_domains, reject_unauth_destination

smtpd_client_restrictions = permit_sasl_authenticated
  • 修改 /etc/postfix/master.cf,讓 Postfix 不要以 chroot 啟動。
    後面的 -v 參數可以用來 Debug,但正式上線時最好拿掉,以免系統被 Log 塞爆了。
(上略)

# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp inet n - n - - smtpd -v

(下略)

或者是新增一個 listen 在 smtps (port 465) 上的 service

# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtps inet n - n - - smtpd
# 強迫 tls 連線 (?)
-o smtpd_tls_wrappermode=yes
# 使用 sasl auth (如果在 main.cf 已經設定了,這行可以省略)
-o smtpd_sasl_auth_enable=yes
# 所有連線到這裡的都必須通過 sasl auth
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
  • 重新啟動 SASL Daemon
/etc/init.d/saslauthd restart

跑起來後,可以用

testsaslauthd -u username -p password

來測試 saslauthd 是否有正常運作

  • 重新啟動 Postfix
/etc/init.d/postfix restart

[編輯] 檢測方式

首先把帳號及密碼轉換成 base64 的編碼:(可能需要安裝 libmime-base64-perl 套件)

perl -MMIME::Base64 -e 'print encode_base64("/0username/0password");'

登入 Postfix:

$ telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 Virtual ESMTP Postfix (Debian/GNU)
EHLO qemu (這裡要輸入的是 HostName)
250-Virtual
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-XVERP
250 8BITMIME
auth plain AHXXXXXXXXXXXXXXXXXXXX8/ (剛才 perl 指令計算的結果)
235 Authentication successful
quit
221 Bye
Connection closed by foreign host.

如果認証成功即表示 SASL 已經正確啟動了。



---------------------------------------------------------------------------------------------------------------
http://www.anti-spam.org.cn/AID/754

Mail::SpamAssassin::Conf - SpamAssassin配置指南

中国反垃圾邮件联盟 王兴宇

2007/11/27


名称

Mail::SpamAssassin::Conf - SpamAssassin 配置指南

英文版原地址 -

http://spamassassin.apache.org/full/3.2.x/doc/Mail_SpamAssassin_Conf.html


修订与译者注

  • 2004/11/13 第一次发布,适用于 SpamAssassin 3.0.x 版本
  • 2007/11/5 更新至 SpamAssassin 3.2.x 版本,并修改了大量用语

中文版翻译 - 中国反 垃圾邮件联盟 (http://anti-spam.org.cn) 王兴 宇

如果译文中有任何错误,欢迎给我发邮件指出,不胜感激。如果希望讨论 SpamAssassin 的相关内容,请到中国反垃圾邮件联盟论 坛 SpamAssassin 版讨论。

译文版本 - 2.0 (最后更新日期:2007/11/27)

名词注释:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值