shisgmei 发表于 2015-9-15 09:56:48

构建postfix邮件服务器(三)启用SMTP用户认证

  一、使用smtp用户认证
  1.发信时无需认证的邮件服务器,很容易造成大量垃圾邮件的产生,也给服务器带来了不必要的负担
  2.SMTP发信认证的常见形式如下:当用户通过SMTP协议向外部邮件域发送邮件时,服务器会要求用户提供用户帐号和口令进行身份认证,只有成功通过身份认证的用户才被允许向外部发送邮件,否则将拒绝发信请求。
  3.Cyrus SASL(Cyrus Simple Authentication and Security Layer,Cyrus简单认证安全层)在RHEL5系统中已默认安装
  4.saslauthd 是Cyrus SASL软件中的一个程序
  
  二、准备
  1.查看系统是否按照cyrus-sasl
  Rpm -qa |grep cyrus
  cyrus-sasl-2.1.22-4
  cyrus-sasl-lib-2.1.22-4
  cyrus-sasl-plain-2.1.22-4
  
  cyrus-sasl-devel-2.1.22-4
http://oneday.cz.cc/wp-content/uploads/2010/02/clip_image002_thumb2.jpg
  三、设置
  (一)设置Cyrus sasl函数库
  cp Sendmail.conf smtpd.conf
  vi /usr/lib/sasl2/smtpd.conf
  输入 pwcheck_method: saslauthd
  
  vi /etc/sysconfig/saslauthd
MECH=shadow
启动sasl的daemon并测试:
# service saslauthd start
# /usr/sbin/testsaslauthd -u 帐号 -p '密码'
0: OK "Success." =>帐号验证成功了
http://oneday.cz.cc/wp-content/uploads/2010/02/clip_image004_thumb3.jpg
  (二)启动saslautthd服务
  service saslauthd start
  chkconfig – –level 35 saslauthd on
http://oneday.cz.cc/wp-content/uploads/2010/02/clip_image006_thumb3.jpg
  (三)修改main.cf配置文件,添加SMTP认证相关的配置参数
  Vi /etc/postfix/main.cf
  smtpd_sasl_auth_enable = yes \\启用SMTP认证
  smtpd_sasl_security_options = noanonymous \\禁止匿名登录
  mynetworks = 127.0.0.1 \\控制可以通过本服务器外发邮件的网络地址或IP地址,设为127.0.0.1是为了确保Webmail系统可正常发送邮件
  smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,rejct_unauth_destion
  \\设置收件人地址过滤规则,其匹配策略是:“从上至下逐条检测,有匹配即停止”。其中:
  permit_mynetworks:允许IP为mynetworks的客户使用本邮件系统寄出邮件
  permit_sasl_authenticated:允许通过SMTP认证的用户向外发送邮件
  reject_unauth_destination:当收件人地址不包括在Postfix的授权网络内时,将拒绝发送该邮件。Postfix的授权网络包括由以下配置参数指定的域及其子域:mydestination、inet_interfaces、virtual_alias_maps、virtual_mailbox_maps、relay_domian
http://oneday.cz.cc/wp-content/uploads/2010/02/clip_image008_thumb3.jpg
  (四)重新加载postfix配置文件
  Postfix reload
  四、测试
  telnet 邮件服务器的25好端口,并且用EHLO宣告客户机的地址,如果出现“250-AUTH PLAIN LOGIN”表明支持认证 (记住这里是EHLO而不是“HELO”)
http://oneday.cz.cc/wp-content/uploads/2010/02/clip_image010_thumb2.jpg
  用telnet进行发信测试
  1)由于采用了认证,则要输入加了密的用户名和密码,加密字符串的编码格式为base64
  2)用printf “用户名” | openssl base64 获得用户名的加密字符串
  用printf “密码” | openssl base64 获得密码的加密字符串
  如获得xiao的用户名及其密码123的加密字符串
  printf “xiao” |openssl base64 得到加密字符串eGlhbw==
  printf “123″ |openssl base64 得到加密字符串MTIz
http://oneday.cz.cc/wp-content/uploads/2010/02/clip_image012_thumb1.jpg
  telnet mail.hongyi.com 25
  Trying 192.168.18.138…
  Connected to mail.hongyi.com (192.168.18.138).
  Escape character is ‘^]’.
  220 mail.hongyi.com ESMTP Postfix
  ehlo localhost //宣告客户机主机地址
  250-mail.hongyi.com
  250-PIPELINING
  250-SIZE 10240000
  250-VRFY
  250-ETRN
  250-AUTH PLAIN LOGIN //表明支持认证
  250-ENHANCEDSTATUSCODES
  250-8BITMIME
  250 DSN
  auth login //用认证的方式登入
  334 VXNlcm5hbWU6
  eGlhbw== //用户名xiao的BASE64编码
  334 UGFzc3dvcmQ6
  MTIz //xiao的密123的BASE64编码
  235 2.7.0 Authentication successful //表明用户通过认证
  mail from: xiao@hongyi.com
  250 2.1.0 Ok
  rcpt to:yy@126.com
  250 2.1.5 Ok
  data
  354 End data with <CR><LF>.<CR><LF>
  this is mail to
  .
  250 2.0.0 Ok: queued as 7BD911BCF43
  quit
  221 2.0.0 Bye
  Connection closed by foreign host.
http://oneday.cz.cc/wp-content/uploads/2010/02/clip_image014_thumb1.jpg
  3)其他知识点
  ①出现535 5.7.8 Error: authentication failed: another step is needed in authentication
  表示输入的BASE64编码有问题
  ②出现554 5.7.1 <qi@126.com>: Relay access denied
  表示为使用SMTP验证时发信失败
  
  本文转自:http://blog.thematice.com作者:稀饭的国度
页: [1]
查看完整版本: 构建postfix邮件服务器(三)启用SMTP用户认证