Main Page | 最近更改 | 編輯本頁 | 頁面歷史

可列印版 | 免責聲明 | 隱私政策

未登入
登入 | 幫助
 

Postfix-SASL

出自DebianWiki

目錄

[編輯] 所需套件

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)

# 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"
mkdir -p /etc/postfix/sasl
echo "pwcheck_method: saslauthd" > /etc/postfix/sasl/smtpd.conf
addgroup postfix sasl
(上略)

# 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
(上略)

# ==========================================================================
# 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                                              
/etc/init.d/saslauthd restart

跑起來後,可以用

testsaslauthd -u username -p password

來測試 saslauthd 是否有正常運作

/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://wiki.debian.org.tw/index.php/Postfix-SASL"

本頁面已經被瀏覽9,707次。 這頁的最後修訂在 2007年5月15日 (星期二) 07:08。 本站的全部文本內容在GNU Free Documentation License 1.2之條款下提供。


[Main Page]
Main Page
社區
近期活動
最近更改
隨機頁面
幫助
贊助

編輯本頁
討論本頁
頁面歷史
鏈入頁面
鏈出更改

特殊頁面
錯誤報告