2022年8月、ホームページを全面リニューアルしました! 情報を分かりやすくお伝えできるサイト作りを目指してまいります。

Postfix + SMTP-AUTH (SASL)のセットアップ!

1. Postfix + SMTP-AUTH (SASL)のセットアップ by FedraCore & VineLinux & RedHatLinux

RedHat系のLinuxでは、rpmで簡単に出来ると思ったら大間違い!saslは、rpmバイナリでインスト出来るがPostfixはソースをゲットしてリビルドが必要である。とにかく、インスト方法を紹介する。 とりあえず便利な機能aptをつかちゃう。

# apt-get update
# apt-get install cyrus-sasl-devel-2.1.15-6 cyrus-sasl-2.1.15-6 cyrus-sasl-md5-2.1.15-6 cyrus-sasl-plain-2.1.15-6

Postfixは、sasl用にカスタマイズするためリビルドする。したがって、aptでソースを落としてくる。

# cd /tmp
# apt-get install postfix-2.0.11-5.src.rpm
# rpm -ivh postfix-2.0.11-5.src.rpm
# cd /usr/src/redhat/SPECS/

# vi postfix.spec

# On Redhat 8.0.1 and earlier, LDAP is compiled with SASL V1 and won’t work
# if postfix is compiled with SASL V2. So we drop to SASL V1 if LDAP is
# requested but use the preferred SASL V2 if LDAP is not requested.
# Sometime soon LDAP will build agains SASL V2 and this won’t be needed.
%if %{LDAP} <= 1 && %{SASL} >= 2
%undefine SASL

%define SASL 1          ← ここのプリプロセッサ定義を1(sasl1)にする。これ多分2はsasl2だと思う(ーー;)

%endif

省略

# rpmbuild -ba /usr/src/redhat/SPECS/postfix.spec
# cd /usr/src/redhat/RPMS/i386/
# rpm -ivh postfix-2.0.11-5.i386.rpm

後の設定は、4項参照。


2.Postfix + SMTP-AUTH (SASL)のセットアップ by Debian

Debianの場合は、パッケージを使う。まず、パッケージのインストール状況確認。

# dpkg -l

ii libsasl-dev 1.5.27-3 Development files for authentication abstrac
ii libsasl-digest 1.5.27-3 DIGEST-MD5 module for SASL
ii libsasl-module 1.5.27-3 Basic Pluggable Authentication Modules for S
ii libsasl7 1.5.27-3 Authentication abstraction library.

上記のパッケージを入れる。

# apt-get install libsasl-dev libsasl-digest libsasl-module libsasl7

Postfixでは、以下のパッケージが必要。

ii postfix 1.1.11-0.woody A high-performance mail transport agent
ii postfix-ldap 1.1.11-0.woody LDAP map support for Postfix
ii postfix-pcre 1.1.11-0.woody PCRE map support for Postfix
ii postfix-tls 1.1.11+tls0.7. TLS and SASL support for Postfix

多分、apt-get installでpostfixをセットアップするとみんな入ってしまうんじゃなかろか。一番必要なのはpostfix本体と、

ii postfix-tls 1.1.11+tls0.7. TLS and SASL support for Postfix
              ↑このモジュール

後の設定は、4項参照。


3.Postfix + SMTP-AUTH (SASL)のセットアップ by FreeBSD

FreeBSDの場合、インストールはPortsでやるので楽だけど後の設定に少々とまどった。基本的には、AUTHデータベースとのやりとりが旨くいけば楽勝(^^)v

1)Portsを使ってまずはインスト

①cyrus-saslのインスト

# cd /usr/ports/security/cyrus-sasl
# make install clean

プラグインモジュールの追加メニューが出てきたら、デフォルトでOK。

②postfixのインスト

# cd /usr/ports/mail/postfix
# make install clean

プラグインモジュール追加メニューが出てきたら、cyrus-saslを選択。


4.SMTP認証の為のアカウント設定(以降、各OS共通)

1)パスワードデータベースの作成

Unixアカウントに対してのSMTP認証パスワードを設定。

# saslpasswd -c -u mail.hogehoge.net hoge
Password: ******
Again (for verification): ******

尚、手前みそだが、SMTP password及びPOP passwordを作成するなら、 この Password Maker が便利だ。

2)データベースに反映されてるかのチェック

# sasldblistusers
user: hoge realm: mail.hogehoge.net mech: PLAIN-APOP
user: hoge realm: mail.hogehoge.net mech: DIGEST-MD5
user: hoge realm: mail.hogehoge.net mech: PLAIN
user: hoge realm: mail.hogehoge.net mech: CRAM-MD5

こうなってれば良い。

3)データベースのアクセス権変更

①FreeBSDの場合

# chgrp postfix /usr/local/etc/sasldb
# chmod 640 /usr/local/etc/sasldb

②FedoraCore & Debianの場合

# chgrp postfix /etc/sasldb
# chmod 640 /etc/sasldb

4)smtpd.conf の作成

①FreeBSDの場合

# vi /usr/local/lib/sasl/smtpd.conf
pwcheck_method:sasldb

を書く。

②FedoraCore & Debianの場合

# vi /usr/lib/sasl/smtpd.conf
pwcheck_method:sasldb

を書く。

5)ハードリンク作成

①FreeBSDの場合

# ln /usr/local/etc/sasldb /var/spool/postfix/etc

②FedoraCore & Debianの場合

# ln /etc/sasldb /var/spool/postfix/etc


5.Postfix main.cfの設定(PostfixでSASLを利用する)

①FreeBSDの場合

# vi /usr/local/etc/postfix/main.cf

②FedoraCore & Debianの場合

# vi /etc/postfix/main.cf

省略

smtpd_sasl_auth_enable = yes                   ← SMTP Authの利用を許可する
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous         
 ← anonymous接続を拒否する
broken_sasl_auth_clients = yes                   
← OutlookExpressから利用する
smtpd_recipient_restrictions = permit_mynetworks,
                     permit_auth_destination,   
← これがないとsmtp受信が出来ないようです
                     permit_sasl_authenticated, 
← SMTP認証を受け付ける条件付け
                     reject_unauth_destination

省略

# postfix check

エラーがなければ、

# postfix start あるいは reload


6.SMTP AUTH動作確認(赤は手入力)

# telnet localhost 25

Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
220 ns.e-linux.net ESMTP Postfix

EHLO localhost

250-ns.e-linux.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-AUTH=LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-XVERP
250 8BITMIME

quit

221 Bye
Connection closed by foreign host


7.パスワードを取り出す

# printf ‘hoge\0hoge\0password’ | mmencode
BB34tcmVjaXBlAGNvLXJlY2

もしくは、

# perl -MMIME::Base64 -e ‘print encode_base64(“username\0username\0password”);’   ← 一行で
BB34tcmVjaXBlAGNvLXJlY2


8.実際に認証してみる(赤は手入力)

# telnet localhost 25

Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
220 ns.e-linux.net ESMTP Postfix

EHLO localhost

250-ns.e-linux.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-AUTH=LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-XVERP
250 8BITMIME

AUTH PLAIN BB34tcmVjaXBlAGNvLXJlY2

235 Authentication successful

quit

221 Bye
Connection closed by foreign host

これで成功。お疲れさま!


9.MUAの設定

メールクライアントの設定は、
http://www.club.kyutech.ac.jp/support/manual/smtpauth.html
を参照するとよいだろう。

以上

コメント