• Twitter
  • rss
  • facebook

緊隨 ROOTLAU.COM 的最新消息和資訊

OpenLDAP-Postfix With SASL2 SMTP Auth 設定

(0)

Category : I.T., Linux

前言

談到 [E-Mail] 就不得不提一下這三個名詞 [MTA][MDA][MUA],關於 [E-Mail] 從使用者發信到收信如何運作可參考 [ twbsd.org - Wang, Chun-Pin 第十六章 郵件伺服器圖解] 了解。

  • MTAMail Transfer Agent:郵件轉送代理人,負責傳送、轉送郵件 (Relay),如:[Sendmail][Postfix][Qmail]
  • MDAMail Delivery Agent:郵件遞送代理人,負責把進來的郵件遞送、過濾到使用者信箱內,如:[Procmail][MailDrop]
  • MUAMail User Agent:郵件使用者代理人,使用者用來發信、收信的程式,如:[Outlook Express][SquirrelMail]

E-Mail 相關服務聆聽埠號 (Listen Port)

  • [SMTP]:25
    • SMTPs (SMTP Over SSL):465
  • [POP3]:110
    • POP3s (POP3 Over SSL):995
  • [IMAP]:143
    • IMAPs (IMAP Over SSL):993

實作環境

  • FreeBSD 6.1-STABLE
  • postfix-2.3.1,1
  • cyrus-sasl-saslauthd-2.1.22

安裝及設定

步驟1.安裝 Postfix 套件

切換至 Ports Tree 路徑安裝 postfix 套件

 #cd /usr/ports/mail/postfix      //切換至套件路徑
 #make install clean              //安裝 postfix 並勾選下列項目
 [X] PCRE      Perl Compatible Regular Expressions   
 [X] SASL2     Cyrus SASLv2 (Simple Auth. and Sec. Layer)   
 [X] TLS       Enable SSL and TLS support                    
 [X] BDB       Berkeley DB (choose version with WITH_BDB_VER)   
 [X] OPENLDAP  OpenLDAP maps (choose ver. with WITH_OPENLDAP_VER)

安裝途中將會尋問二個問題

 1.You need user "postfix" added to group "mail".Would you like me to add it [y]? y   //是否將 postfix 加入 mail 群組,此例回答 y
 2.Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y                 //是否在 /etc/mail/mailer.conf 中啟動 Postfix,此例回答 y

安裝完後系統還會貼心的提醒說 如果使用 SASL 認證的方式,必須確定 postfix 這個代理使用者有權力讀取 sasldb 的檔案

 If you are using SASL, you need to make sure that postfix has access to read the sasldb file.
 This is accomplished by adding postfix to group mail and making the /usr/local/etc/sasldb* file(s) readable by group mail (this shouldbe the default for new installs).

步驟2.設定 Postfix 能讀取 SASL 設定檔

查看 SASL 設定檔知道其擁有人 (owner) 及群組 (groups) 為 cyrus 因此我們將 postfix 加入此群組 (cyrus) 內,以便屆時 postifx 服務能順利讀取 SASL 設定檔。

 #ls -l /usr/local/etc/sasldb*                    //查看 sasldb 權限
 -rw-r-----  1 cyrus  mail  16384  7 27 11:36 /usr/local/etc/sasldb2.db

修改群組 (group) 檔案將 postfix 加入 cyrus 群組

 #vi /etc/group                                   //修改群組檔案
 cyrus:*:60:postfix                               //將 postfix 加入 cyurs 群組內

步驟3.安裝 Cyrus-Sasl2-Saslauthd 套件

切換至 Ports Tree 路徑安裝 Cyrus-Sasl2-Saslauthd 套件

 #cd /usr/ports/security/cyrus-sasl2-saslauthd    //切換至套件路徑
 #make install clean                              //安裝 SASL2 套件

安裝完後系統仍貼心提醒你要使用 SASL 功能記得在 rc.conf 內加上 saslauthd_enable=”YES”

 To run saslauthd from startup, add saslauthd_enable="YES" in your /etc/rc.conf.

步驟4.檢查 /etc/master.passwd 及 /etc/group

由於安裝 postfix 時系統會新增 postfix 這個使用者及群組,但這樣的動作將會我們破壞我們在 OpenLDAP-PAM NSS 設定 這篇的設定,因此記得修改回來吧!! (否則將造成登入失敗)

修改系統使用者密碼及群組檔案,將認證部份導至 LDAP

 #vipw
 postfix:*:125:125::0:0:Postfix Mail System:/var/spool/postfix:/usr/sbin/nologin
 +:*::::::::                //確保此行在最後一行
 #vim /etc/group
 postfix:*:125:
 +:*:0:                     //確保此行在最後一行

步驟5.修改 /etc/rc.conf

修改 /etc/rc.conf 加入啟動相關服務設定,以便系統重新開機時能自動帶起 Postfix、SASL 服務,由於我們 [MTA] 採用 Postfix 所以記得將 Sendmail 服務關閉。

 #vi /etc/rc.conf
 sendmail_enable="NO"       //關閉 Sendmail
 postfix_enable="YES"       //啟動 Postfix 服務
 saslauthd_enable="YES"     //啟動 SASL 服務

關於 Sendmail 於 rc.conf 內設定 None、No、Yes 意義?

  1. None:將 Sendmail 完全關閉
  2. NO:Sendmail 只監聽 Localhost (127.0.0.1:25)
  3. YES:啟用 Sendmail

步驟6.建立 smtpd.conf

修改 SMTP 設定檔

 #vi /usr/local/lib/sasl2/smtpd.conf                        //修改 SMTP 設定檔
 pwcheck_method: saslauthd                                  //修改認證方法
 mech_list: plain login cram-md5 digest-md5                 //修改認證方式

步驟7.修改 postfix 設定檔 main.cf

修改 Postfix 設定檔 main.cf,以下僅列出基本設定 (即僅列出修改項目)

 myhostname = mail.weithenn.org
 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
 mynetworks_style = subnet
 mynetworks = 192.168.1.0/24, 127.0.0.0/8, 61.60.59.58/32   //指定 LAN 網段及 Public IP
 alias_maps = hash:/usr/local/etc/postfix/aliases           //預設使用 /etc/aliases
 home_mailbox = Maildir/                                    //採用 MailDir 方式收取 E-Mail

啟動 Authenticated Relay 功能

 broken_sasl_auth_clients = yes
 smtpd_sasl_auth_enable = yes
 smtpd_sasl_security_options = noanonymous
 smtpd_sasl_local_domain = $myhostname
 smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_relay_domains,
 smtpd_client_restrictions = permit_sasl_authenticated

步驟8.建立別名 (Aliases) 資料庫

建立 E-Mail 別名 (Aliases) 資料庫也就是產生 /usr/local/etc/postfix/aliases.db 檔案鍵入如下指令即可,或執行 newaliases 指令。

 #postalias /usr/local/etc/postfix/aliases

步驟9.停止/啟動相關服務

由於我們 [MTA] 採用 Postfix 所以在啟動 Postfix 服務以前記得先將 Sendmail 服務關閉。

 #/etc/rc.d/sendmail stop                     //停止 Sendmail 服務 
 Stopping sendmail_submit.
 #/usr/local/etc/rc.d/postfix start           //啟動 Postfix 服務
 postfix/postfix-script: starting the Postfix mail system
 #/usr/local/etc/rc.d/saslauthd start         //啟動 SASL 服務
 Starting saslauthd.

步驟10.測試 SMTP Auth 功能

Postfix 及 SASL 服務成功啟動後可依如下方式來測試 SMTP Authentication 機制是否作用了

 #telnet localhost 25                         //連結至本機 SMTP
 Trying ::1...
 Trying 127.0.0.1...
 Connected to localhost.weithenn.org.      
 Escape character is '^]'.
 220 mail.weithenn.org ESMTP Postfix          //若前述步驟未執行 postalias 將不會出現此行也就是 postfix 啟動但卻找不到 DB
 ehlo localhost                               //測試 SASL 機制 (此行為自行輸入)
 250-mail.weithenn.org
 250-PIPELINING
 250-SIZE 10240000
 250-VRFY
 250-ETRN
 250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5     //主機回應 SMTP AUTH LOGIN 成功
 250-AUTH=LOGIN PLAIN DIGEST-MD5 CRAM-MD5     
 250-ENHANCEDSTATUSCODES
 250-8BITMIME
 250 DSN
 quit                                         //離開 (此行為自行輸入)
 221 2.0.0 Bye
 Connection closed by foreign host.

若使用的 [MUA] 為 Outlook Express 則請勾選 我的伺服器需要驗證 項目才能順利使用 Outlook Express 發送信件,如下圖所示

Outlook Express - 我的伺服器需要驗證

當 [MUA] 通過 SASL 驗證機制寄信成功 Maillog 訊息,類似如下

 Aug 26 13:57:42 ldap postfix/smtpd[51569]: 8722B5C3A: client=weithenn.lan.home[192.168.1.11], sasl_method=LOGIN, sasl_username=weithenn@weithenn.org



轉載自:http://www.weithenn.org/cgi-bin/wiki.pl?OpenLDAP-Postfix_With_SASL2_SMTP_Auth_%E8%A8%AD%E5%AE%9A#Heading15

CentOS5.1 安裝 OpenWebMail

(0)

Category : Linux

新安裝了CentOS 5.1版,(64位元版),仍舊使用Sendmail作為郵件伺服器,現要安裝Openwebmail,使用yum(已使用管理員權限):

* cd /etc/yum.repos.d
* get ftp://openwebmail.org/pub/yum/openwebmail.repo
* yum install openwebmail

接下來只要按下「y」,讓程式自動執行就可以了,比以前要安裝許多的相關附屬套件,真是輕鬆多了!

參考網頁:http://openwebmail.org/openwebmail/download/redhat/yum/readme.txt

Zend 原來也可以通過 yum 來安裝

(0)

Category : Linux

Linux CentOS 5 Server: YUM Repository to Install Zend Optimizer

I recently needed to install Zend Optimizer which was required by a ZenCart addon using Zend Guard. Zend Guard encrypts some or all of a PHP application to help protect its contents from being copied or modified. So I was typically like to install everything on CentOS using the yum package manger to make sure that updates for all applications are uniform and easy to do.

The actual package that needs to be installed to install Zend Optimizer is called php-zend-optimizer and isn’t readily available in many yum repositories. On a typical CentOS installation I add a couple extra yum repos including rpmforge and a repo that provides ruby based packages for CentOS. Anyhow after awhile of searching I finally located the atomic repository which did include the php-zend-optimizer package.

Install Atomic Repository On a CentOS Server:

  1. wget -q -O – http://www.atomicorp.com/installers/atomic.sh | sh

The above command will download the atomic.sh script and then execute it. First the script installs the Atomic GPG key. Unless you have a Plesk server that you want packages for you can answer “n” when asked if you want to enable the Plesk yum repository. After this it will install the atomic.repo file in /etc/yum.repos.d/ directory. Its contents are located below.

Contents: atomic.repo

  1. # Name: Atomic Rocket Turtle RPM Repository for CentOS / Red Hat Enterprise Linux 5 -
  2. # URL: http://www.atomicrocketturtle.com/
  3. [atomic]
  4. name = CentOS / Red Hat Enterprise Linux $releasever – atomicrocketturtle.com
  5. mirrorlist = http://www.atomicorp.com/mirrorlist/atomic/centos-5-$basearch
  6. #mirrorlist = http://www.atomicorp.com/channels/atomic/centos/5/mirrors-atomic
  7. enabled = 1
  8. priority = 1
  9. protect = 0
  10. gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY.art.txt
  11. gpgcheck = 1
  12. # Almost Stable, release candidates for [atomic]
  13. [atomic-testing]
  14. name = CentOS / Red Hat Enterprise Linux $releasever – atomicrocketturtle.com – (Testing)
  15. mirrorlist = http://www.atomicorp.com/mirrorlist/atomic-testing/centos-5-$basearch
  16. enabled = 0
  17. priority = 1
  18. protect = 0
  19. gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY.art.txt
  20. gpgcheck = 1
  21. # Untested, Unstable, known buggy, and incomplete packages.
  22. #[atomic-bleeding]
  23. #name = CentOS / Red Hat Enterprise Linux $releasever – atomicrocketturtle.com – (Bleeding)
  24. #baseurl = http://www.atomicorp.com/channels/atomic-bleeding/centos/5/$basearch/
  25. #enabled = 0
  26. #priority = 1
  27. #protect = 0
  28. #gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY.art.txt
  29. #gpgcheck = 1

By default only the atmoic yum repository is installed however you can also enable the atomic-testing repository and atomic-bleeding repository. Once installed issued the below command to install php-zend-optimizer.

  1. yum install php-zend-optimizer

Now that Zend Optimizer is installed you can run PHP applications protected by Zend Guard. The Zend Optimizer package is now easily managed with the yum package manager.


SquirrelMail + poppassd

(0)

Category : Linux

不管輸入的密碼是多麼的正確,一律給錯:

很久沒有替別人安裝過 Mail Server 了,那個 Fedora Core 8 真了得‧‧‧

除了給那個 Bind 玩耍了幾天外,Poppassd 也攪了我十數個小時‧‧‧

那個 bind 竟然不許其他 ip 查詢‧‧‧

而 Poppassd 就錯漏百出‧‧‧

500 Old password is incorrect

查了半天程式、 log 、網路,不斷搜尋資料,一直找不到原因,直到看到有人提到 /etc/pam.d/poppassd 裡面

#%PAM-1.0
auth required pam_pwdb.so shadow nullok
account required pam_pwdb.so
password required pam_cracklib.so retry=3
password required pam_pwdb.so use_authtok nullok

使用的 pam_pwdb.so ,但是系統上沒有這個檔案 O_O 。仔細一查,奇了, 竟然真的找不到這個檔案。

知道原因,就好辦。仔細查了一下, 在 pam 套件裡,真的沒提供 pam_pwdb.so 。而 pam_pwdb.so 與 pam_unix.so 是相同功能的模組,於是解決方法就很簡單了:

cd /lib/security
ln -s pam_unix.so pam_pwdb.so

建立一個 soft link ,用 pam_unix.so 來提供 pam_pwdb.so 的功能,搞定!

但是,要求的 password 就很有要求了,我敢肯定用戶不大可能記到這樣子的密碼‧‧‧ >_<

相信不足三、二天就一定會有人走來跟我說忘記了密碼;還需努力,再找!

修改 /etc/pam.d/poppassd

刪除 pam_cracklib.so 這一行 (在這行的前面加 # 號)

在這行 “password required /lib/security/pam_unix.so use_authtok nullok”

刪除 pam_unix.so 後面的 “use_authtok”

終於可以睡覺了,但太陽伯伯已經出來!‧‧‧ z… z… Z…

Ubuntu 8.04 LTS Server

(0)

Category : Linux

當我收到 Ubuntu 8.04 LTS Server 這張光盤時,興致勃勃地開始安裝‧‧‧

由一開始接觸 Linux 就是使用 Redhat,別的就從沒有用過;聽說 Ubuntu 是個不錯的 distrubtion。

開始安裝時,也是得簡單,整過過程也不難,好像少了些什麼似的‧‧‧

但是當安裝完時竟然無法以 root 登入,即時 O 晒嘴;對了,安裝時好像並沒有問 root 的密碼!只有使用安裝時建立的用戶登入好了。

最後在線上找到了些有關於 Ubuntu Server 的資訊,原來她是把 root 的帳戶 disable 了,是為了安全吧了。如果要使用只有 root 才能使用的指令,就只得在指令前加上 sudo 才可以使用。

如果要一直使用 root 的身份,可以使用以下指令:

sudo -i

如果要啟動 root 的帳戶,可以使用以下指令:

sudo passwd root

如果要關閉 root 的帳戶,可以使用以下指令:

sudo passwd -l root

也可以在安裝時按 [F6] 進入進階模式,那裡可以啟動 root 的帳號並設定密碼。

解決 dovecot POP3 收信時發生 Mailbox / INBOX 錯誤的問題

(0)

Category : Linux

解決 dovecot POP3 收信時發生 Mailbox / INBOX 錯誤的問題

版本: dovecot-0.99.13-3.FC3

maillog:

pop3(某帳號): Error syncing mbox file /var/mail/某帳號: LF not found where expected
pop3(某帳號): Error indexing mbox file /var/mail/某帳號: LF not found where expected
pop3(某帳號): Couldn’t open INBOX: Internal error occured. Refer to server log for more information.

以 telnet 登入 110 埠:

輸入完密碼後回應: -ERR No INBOX for user.

版本: dovecot-1.0-0.beta2.7

maillog:

pop3(某帳號): Mailbox init failed top=0/0, retr=0/ del=0/0, size=0

Outlook Express 訊息:

登入您的郵件伺服器時發生錯誤。您的密碼被拒絕。…通訊協定: POP3, 伺服器回應: ‘-ERR Mailbox isn’t a valid mbox file’,… 伺服器錯誤: 0x800CCC90, 錯誤碼: 0x800CCC92

解決方法:

以下以 foo 代表某帳號

cd /var/spool/mail
cp foo foo_ 備份郵件
true > foo 清空郵箱

另外寄一封信到 foo 帳號

cat foo_ >> foo 匯入剛剛備份的郵件

即可正常收信

from: http://cha.homeip.net/blog/archives/2006/06/mis.html

在 Linux 的 shell 上搜尋文字並替代

Comments Off

Category : I.T., Linux

今天真的忙過死去活來!在決定放棄使用 Pacific Internet 的寬頻而改用 PCCW 的一刻,已經知道會有這一天的來臨‧‧‧ 無耐 Pacific Internet 實在不爭氣,連我這個 Reseller Partner 也要‧‧‧

接著就是要將我的 Servers (幾部) 的網絡設定,DNS,HTTPD,SENDMAIL,‧‧‧ 全部也要將 IP 更換下來,痛苦‧‧‧

幸好徙網路上找到了一個可以將文字更換的程式,工作就可以比較輕鬆地完成!

#!/bin/bash
#       This script will search and replace all regular files for a string
#       supplied by the user and replace it with another string.
#
#       Written by Daniel McCarthy
# daniel.mccarthy@linuxphile.org
#
function usage {
echo “”
echo “Search/replace script”
echo ”    Written by Daniel McCarthy”
echo ” daniel.mccarthy@linuxphile.org”
echo ” http ://linuxphile.org”
echo “”
echo “Not enough parameters provided.”
echo “Usage: ./$0 searchstring replacestring”
echo “Remember to escape any special characters in the searchstring or the replacestring”
echo “”
}

#check for required parameters
if  [ ${ #1 } -gt 0  ]  &&  [ ${ #2 } -gt 0  ];
then
for f in `find  -type f`;
do
if grep -q $1 $f;
then
cp $f $f.bak
echo “The string $1 will be replaced with $2 in $f”
sed s/$1/$2/g < $f.bak > $f
rm $f.bak
fi
done

else
#print usage informamtion
usage
fi

參考:http://linuxphile.org/node/13

更改 root 的密碼

(0)

Category : Linux

有不少朋友至電給小 root 問有關於如更改 root 的密碼,當然不是我的私人密碼啦!是 Linux 管理員帳戶 root 的密碼。

All you need to do is reboot the machine. When you are presented with the Grub menu, hit the ‘e’ key. This will allow you to edit the current boot options. Add the ‘ single’ to the line that begins with ‘kernel /vmlinuz’.  Now press ‘b’ to boot with the modified boot options.

You’ll now be presented with the command line. At the command line simply enter ‘passwd’. You’ll be prompted, twice, for a new password.

Type in ‘exit’ and the machine will continue booting into the normal process. Your root password has now been changed.

轉自:http://linuxphile.org/node/15

Adding GD PHP support to Fedora Core 5 (FC5)

(0)

Category : Linux

A simple way to install PHP-PD in FC5

% yum install gd-devel
% yum install php-gd

restart apache:
% /sbin/service httpd restart

http://iamcam.wordpress.c……pport-to-fedora-core-5-fc5/