Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Unix知識 >> Unix教程

實作帶 SMTP 認證的 Postfix 郵件系統(FreeBSD)

以下流程在 FreeBSD 4.9 實測通過,同樣適用於 FreeBSD 5.2.1。用到的元件版本為 cyrus-sasl-2.1.15、postfix-2.0.18、qpopper4.0.4。

1. 安裝 cyrus-sasl-2.1.15

ms# tar -zxvf cyrus-sasl-2.1.15.tar.gz
ms# cd cyrus-sasl-2.1.15
ms# ./configure --disable-sample --disable-pwcheck --disable-cram --disable-digest --disable-krb4 --disable-gssapi --disable-anon --enable-plain --enable-login
ms# make
ms# make install
ms# ln -s /usr/local/lib/sasl2 /usr/lib/sasl2

2. 配置 sasl 的 lib 庫

ms# edit /etc/default/rc.conf(在 ldconfig_paths="/usr/loca/lib 後面加上 /usr/local/lib/sasl2)
ms# shutdown -r now(使其生效)

3. 建立 saslauthd 狀態目錄

ms# mkdir /var/state/saslauthd

4. 準備 Postfix 認證設定檔

使用 saslauthd 呼叫 pam 認證:
ms# echo pwcheck_method: saslauthd > /usr/lib/sasl2/smtpd.conf

5. 安裝 postfix-2.0.18(先停用 sendmail)

ms# mv /usr/bin/newaliases /usr/bin/newaliases.OFF
ms# mv /usr/bin/mailq /usr/bin/mailq.OFF
ms# mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
ms# mv /etc/rc.sendmail /etc/sendmail.OFF
ms# ee /etc/rc.conf(把 sendmail="YES" 前加 # 註解掉,或改成 sendmail="NO")

6. 新增 postfix 相關帳號與群組

ms# pw groupadd postfix -g 2003
ms# pw groupadd postdrop -g 2004
ms# pw useradd postfix -u 2003 -g 2003 -d /dev/null -s /nologin

7. 編譯安裝原始碼

解開後會產生 /tmp/postfix-2.0.18 目錄。

ms# tar xvzf postfix-2.0.18.tar.gz
ms# cd /tmp/postfix-2.0.18
ms# make -f Makefile.init makefiles 'CCARGS=-DUSE_SASL_AUTH -I/usr/local/include/sasl' 'AUXLIBS=-L/usr/local/lib/ -lsasl2 '
ms# make install
ms# echo 'postfix: root' >> /etc/aliases(或 ee /etc/aliases 手動加入 postfix: root)
ms# /usr/bin/newaliases

8. 設定開機自啟

ms# ee /usr/local/etc/rc.d/postfix-server.sh(加入 postfix start)
ms# chmod 755 /usr/local/etc/rc.d/postfix-server.sh

9. 再次確認帳號

ms# pw groupadd postfix -g 2003
ms# pw groupadd postdrop -g 2004
ms# pw useradd postfix -u 2003 -g 2003 -d /dev/null -s /nologin

10. 重啟

重開機後若 postfix 沒有自啟,手動執行:
ms# postfix start

11. 安裝 qpopper

ms# ln –s /var/spool/mail/ /usr/mail
ms# cd /tmp
ms# tar xvzf qpopper4.0.13
ms# cd /tmp/qpopper4.0.13
ms# ./configure
ms# make
ms# make install(完成後 popper 位於 /usr/local/sbin/)

12. 配置 POP3

ms# ee /etc/inetd.conf,找到 POP3 相關內容改為:
pop-3 stream tcp nowait root /usr/local/sbin/popper popper -s

13. 配置 main.cf 開啟 SMTP 認證

在 /etc/postfix/main.cf 末尾加上:

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated permit_auth_destination reject
#smtpd_sasl_local_domain = $mydomain
smtpd_client_restrictions = permit_sasl_authenticated

14. 新增郵件帳號

ms# pw useradd 用戶名
ms# password 用戶名

15. 啟動認證服務並建立密碼

ms# saslauthd –a pam
ms# /usr/local/sbin/saslpasswd2 用戶名(依提示輸入密碼)

16. 用戶端設定

郵件接收程式(如 Outlook Express)記得勾選「需要 SMTP 認證」。

Copyright © Linux教程網 All Rights Reserved