[转] Debian+Postfix-SASL认证配置全解

简介:
Debian+Postfix-SASL认证配置全解

 

目录  
所需套件  
2 Mail Relay 
简介  
 Postfix  支援  Cyrus-SASL? V2  认证:( Debian Sarge  
检测方式  

所需套件  
postfix-tls sasl2-bin libsasl2-modules 
apt-get install  postfix-tls sasl2-bin libsasl2-modules

Mail Relay 
简介  
所谓的  Mail Relay ,指的就是  Mail Server  会不会替使用者将信转寄到外部去。  

比如说,我将信寄给  [email]tetralet@pchome.com.tw[/email] ,如果  [email]tetralet@pchome.com.tw[/email]  这个信箱并不是位于本机上,那么这封信将会转给 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  已经正确启动了。

本文转自yahoon 51CTO博客,原文链接:http://blog.51cto.com/yahoon/40091,如需转载请自行联系原作者
相关文章
|
Ubuntu 安全 Linux
Linux(34)Rockchip RK3568 Ubuntu22.04和Debian 10上配置远程桌面工具
Linux(34)Rockchip RK3568 Ubuntu22.04和Debian 10上配置远程桌面工具
1339 0
百度搜索:蓝易云【在Debian上安装配置Klipper教程】
通过按照以上步骤,你应该能够在Debian上成功安装和配置Klipper。请根据你的具体打印机型号和配置需求进行相应的调整。如果遇到任何问题,可以参考Klipper官方文档或社区寻求更多帮助。
389 0
|
网络安全
如何在 Debian 系统上配置 NTP,来确保计算机时间的准确同步
如何在 Debian 系统上配置 NTP,来确保计算机时间的准确同步
4025 0
如何在 Debian 系统上配置 NTP,来确保计算机时间的准确同步
|
Linux 容器 Docker
Debian配置系统中文语言及环境
Debian配置系统中文语言及环境
11574 1
|
监控 网络协议 安全
如何在 Debian 下配置邮件服务器
本教程将讨论如何在Debian(或Ubuntu)配置一个可工作的邮件服务器。我们知道在邮件服务器使用的主要协议有SMTP、POP和IMAP。在本教程中,SMTP协议使用postfix,POP/IMAP协议使用dovecot。
5323 0
|
10月前
|
Ubuntu Shell 开发工具
ubuntu/debian shell 脚本自动配置 gitea git 仓库
这是一个自动配置 Gitea Git 仓库的 Shell 脚本,支持 Ubuntu 20+ 和 Debian 12+ 系统。脚本会创建必要的目录、下载并安装 Gitea,创建 Gitea 用户和服务,确保 Gitea 在系统启动时自动运行。用户可以选择从官方或小绿叶技术博客下载安装包。
389 2
|
安全 Linux 网络安全
百度搜索:蓝易云 ,Linux Debian11服务器安装SSH,创建新用户并允许SSH远程登录,及SSH安全登录配置!
这些步骤提供了在Debian 11服务器上安装SSH,创建新用户并允许SSH远程登录以及进行SSH安全登录配置的指南。请确保按照步骤操作,并根据您的需求进行必要的修改。
271 0
|
安全 Linux 网络安全
如何在Debian 9上安装和配置VNC
如何在Debian 9上安装和配置VNC
316 0
|
网络协议 算法 网络安全
如何在 Debian Wheezy 上使用 Postfix 安装和配置 DKIM
如何在 Debian Wheezy 上使用 Postfix 安装和配置 DKIM
286 0
|
Java 应用服务中间件 Apache
在 Debian 服务器上安装和配置 Apache Tomcat 的方法
在 Debian 服务器上安装和配置 Apache Tomcat 的方法
165 0