メールサーバー · 3 min read · Feb 13, 2026

Postfix-SMTP-AUTH-TLS-Howto

Postfix-SMTP-AUTH-TLS-Howto

Version 1.0
Author: Falko Timme

この文書は、SMTP-AUTHおよびTLSに対応したPostfixに基づくメールサーバーのインストール方法を説明します。すべての*nixオペレーティングシステムで動作するはずです(パスなどに関して若干の変更が必要な場合があります)。これまでのところ、Debian WoodyおよびFedora Core 1でテストしました。

このハウツーは実用的なガイドとして意図されており、理論的な背景についてはカバーしていません。それらはウェブ上の他の多くの文書で扱われています。

この文書は、いかなる種類の保証もなく提供されます!

1 ソースを取得する

以下のソフトウェアが必要です:openssl、cyrus-sasl2、postfix、およびpostfix用のTLSパッチ。ソフトウェアは/tmpディレクトリからインストールします。

cd /tmp
wget http://www.openssl.org/source/openssl-0.9.7c.tar.gz
wget –passive-ftp ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.17.tar.gz
wget –passive-ftp ftp://ftp.aet.tu-cottbus.de/pub/postfix_tls/related/postfix/postfix-2.0.16.tar.gz
wget –passive-ftp ftp://ftp.aet.tu-cottbus.de/pub/postfix_tls/pfixtls-0.8.16-2.0.16-0.9.7b.tar.gz

2 Opensslをインストールする

tar xvfz openssl-0.9.7c.tar.gz
cd openssl-0.9.7c
./config
make
make install

3 Cyrus-saslをインストールする

cd /tmp
tar
xvfz cyrus-sasl-2.1.17.tar.gz
cd cyrus-sasl-2.1.17
./configure –enable-anon –enable-plain –enable-login –disable-krb4 –with-saslauthd=/var/run/saslauthd
–with-pam –with-openssl=/usr/local/ssl –with-plugindir=/usr/local/lib/sasl2
–enable-cram –enable-digest –enable-otp
(1行!)
make
make install

もし/usr/lib/sasl2が存在する場合:
mv /usr/lib/sasl2 /usr/lib/sasl2_orig

ln -s /usr/local/lib/sasl2
/usr/lib/sasl2

ファイル/usr/local/lib/sasl2/smtpd.confを作成します:

| # これはsmtpdがsaslauthdデーモンを使用して認証するように設定します。 pwcheck_method:saslauthd # これはplain、login、cram-md5、およびdigest-md5のみを認証メカニズムとして許可します。 mech_list: plain login cram-md5 digest-md5 |

4 Postfixをインストールする

cd /tmp
tar xvfz pfixtls-0.8.16-2.0.16-0.9.7b.tar.gz
tar xvfz postfix-2.0.16.tar.gz
cd postfix-2.0.16
useradd postfix
groupadd postdrop
patch -p1 < ../pfixtls-0.8.16-2.0.16-0.9.7b/pfixtls.diff
make makefiles CCARGS=”-DHAS_SSL -DUSE_SASL_AUTH -I/usr/local/include/sasl
-I/usr/local/ssl/include” AUXLIBS=”-L/usr/local/ssl/lib -L/usr/local/lib
-R/usr/local/lib -lsasl2 -lssl -lcrypto”
(1行!)
make
make install
(デフォルト値を受け入れます)

  • cp /etc/postfix/aliases /etc/
    newaliases*

ファイル/etc/init.d/postfixを作成します:

| #!/bin/bash # # postfix このスクリプトはpostfixデーモンを制御します。 # # 説明: Postfix MTA # プロセス名: postfix case "$1" in start) /usr/sbin/postfix start ;; stop) /usr/sbin/postfix stop ;; reload) /usr/sbin/postfix reload ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|reload|restart}" exit 1 esac exit 0 |

chmod 755 /etc/init.d/postfix

postfixをブート時に起動するために、以下を実行します:

ln -s /etc/init.d/postfix
/etc/rc2.d/S20postfix
ln -s /etc/init.d/postfix /etc/rc3.d/S20postfix
ln -s /etc/init.d/postfix /etc/rc4.d/S20postfix
ln -s /etc/init.d/postfix /etc/rc5.d/S20postfix
ln -s /etc/init.d/postfix /etc/rc0.d/K20postfix
ln -s /etc/init.d/postfix /etc/rc1.d/K20postfix
ln -s /etc/init.d/postfix /etc/rc6.d/K20postfix

私たちのpostfixは/var/spool/postfix内でchrootされて実行されるため、いくつかのファイルをコピーする必要があります:

mkdir -p /var/spool/postfix/etc
cd /etc
cp localtime services hosts resolv.conf /var/spool/postfix/etc/
mkdir -p /var/spool/postfix/var/run
mv -f /var/run/saslauthd/ /var/spool/postfix/var/run/
chmod 755 /var/spool/postfix/var/run/saslauthd/
ln -s /var/spool/postfix/var/run/saslauthd/ /var/run/saslauthd

次に、TLSに必要な証明書ファイルを生成する必要があります:

mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/

もし/usr/bin/opensslが存在する場合:

mv /usr/bin/openssl /usr/bin/openssl _orig

ln -s /usr/local/ssl/bin/openssl
/usr/bin/openssl
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024

<- smtpd.keyのパスワードを入力します。

chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr

<- 再度、smtpd.keyのパスワードを入力します。
<- 国名を入力します(例:「DE」)。
<- 州または県名を入力します。
<- 市名を入力します。
<- 組織名を入力します(例:会社名)。
<- 組織単位名を入力します(例:「IT部門」)。
<- システムの完全修飾ドメイン名を入力します(例:「server1.example.com」)。
<- メールアドレスを入力します。

以下の情報はオプションです:

<- チャレンジパスワードを入力します。
<- オプションの会社名を入力します。

openssl x509 -req -days
3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt

<- 再度、smtpd.keyのパスワードを入力します。

openssl rsa -in smtpd.key
-out smtpd.key.unencrypted

<- 再度、smtpd.keyのパスワードを入力します。 *
*

mv -f smtpd.key.unencrypted
smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

<- 再度、smtpd.keyのパスワードを入力します。
<- 国名を入力します(例:「DE」)。
<- 州または県名を入力します。
<- 市名を入力します。
<- 組織名を入力します(例:会社名)。
<- 組織単位名を入力します(例:「IT部門」)。
<- システムの完全修飾ドメイン名を入力します(例:「server1.example.com」)。
<- メールアドレスを入力します。

SMTP-AUTHおよびTLSを有効にするために/etc/postfix/main.cfを編集します:

*postconf -e ‘mydomain = example.com’
postconf -e ‘myhostname = server1.$mydomain’
postconf -e ‘smtpd_sasl_local_domain =’
postconf -e ‘smtpd_sasl_auth_enable = yes’
postconf -e ‘smtpd_sasl_security_options = noanonymous’
postconf -e ‘broken_sasl_auth_clients = yes’
postconf -e ‘smtpd_recipient_restrictions=permit_sasl_authenticated,permit_mynetworks,check_relay_domains’
postconf -e ‘inet_interfaces = all’
postconf -e ‘alias_maps = hash:/etc/aliases’

  • postconf
    -e ‘smtpd_tls_auth_only = no’
    postconf -e ‘smtp_use_tls = yes’
    postconf -e ‘smtpd_use_tls = yes’
    postconf -e ‘smtp_tls_note_starttls_offer = yes’
    postconf -e ‘smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key’
    postconf -e ‘smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt’
    postconf -e ‘smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem’
    postconf -e ‘smtpd_tls_loglevel = 1’
    postconf -e ‘smtpd_tls_received_header = yes’
    postconf -e ‘smtpd_tls_session_cache_timeout = 3600s’
    postconf -e ‘tls_random_source = dev:/dev/urandom’

5 Saslauthdを設定する

ファイル/etc/init.d/saslauthdを作成します:

| #!/bin/sh -e NAME=saslauthd DAEMON="/usr/sbin/${NAME}" DESC="SASL Authentication Daemon" DEFAULTS=/etc/default/saslauthd test -f "${DAEMON}" || exit 0 # デフォルトファイルをソースします。このファイルを編集してこのスクリプトを設定します。 if [ -e "${DEFAULTS}" ]; then . "${DEFAULTS}" fi # デーモンを起動しない場合は、単に終了します。 if [ "${START}" != "yes" ]; then exit 0 fi # 定義されたメカニズムがない場合 if [ "x${MECHANISMS}" = "x" ]; then echo "使用するメカニズムで${DEFAULTS}を設定する必要があります" exit 0 fi # 必要なフラグを持つメカニズムを追加します。 for i in ${MECHANISMS}; do PARAMS="${PARAMS} -a ${i}" done # オプションを考慮します。 case "${1}" in start) echo -n "${DESC}を開始しています: " ln -fs /var/spool/postfix/var/run/${NAME} /var/run/${NAME} ${DAEMON} ${PARAMS} echo "${NAME}." ;; stop) echo -n "${DESC}を停止しています: " PROCS= `ps aux | grep -iw '/usr/sbin/saslauthd' | grep -v 'grep' |awk '{print $2}' | tr ' ' ' '` if [ "x${PROCS}" != "x" ]; then kill -15 ${PROCS} &> /dev/null fi echo "${NAME}." ;; restart|force-reload) $0 stop sleep 1 $0 start echo "${NAME}." ;; *) echo "Usage: /etc/init.d/${NAME} {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0 |

chmod 755 /etc/init.d/saslauthd

saslauthdをブート時に起動するために、以下を実行します:

ln -s /etc/init.d/saslauthd
/etc/rc2.d/S20saslauthd
ln -s /etc/init.d/saslauthd /etc/rc3.d/S20saslauthd
ln -s /etc/init.d/saslauthd /etc/rc4.d/S20saslauthd
ln -s /etc/init.d/saslauthd /etc/rc5.d/S20saslauthd
ln -s /etc/init.d/saslauthd /etc/rc0.d/K20saslauthd
ln -s /etc/init.d/saslauthd /etc/rc1.d/K20saslauthd
ln -s /etc/init.d/saslauthd /etc/rc6.d/K20saslauthd

次に、ファイル/etc/default/saslauthdを作成します:

| # saslauthdが自動的に実行される前に、これをコメント解除する必要があります。 START=yes # 使用したい認証メカニズムを指定する必要があります。 # これはPAMサポートのためにデフォルトで「pam」ですが、 # 「shadow」または「sasldb」も含めることができます。 MECHANISMS=shadow |

saslauthd/usr/local/sbinにあることがわかった場合は、シンボリックリンクを作成します:

ln -s /usr/local/sbin/saslauthd
/usr/sbin/saslauthd

次に、saslauthdpostfixを起動します:

/etc/init.d/saslauthd start

/etc/init.d/postfix start

6 設定をテストする

SMTP-AUTHおよびTLSが正しく機能するかどうかを確認するには、次のコマンドを実行します:

telnet
localhost 25

Postfixメールサーバーへの接続が確立されたら、次のように入力します:

ehlo
localhost

次の行が表示される場合、すべて正常です:

250-STARTTLS

および

250-AUTH

quitと入力して、システムのシェルに戻ります。

このトピックに関するさらなる(Debian特有の)情報は、こちらにあります:http://www.projektfarm.com/en/support/debian_setup/index.html。

リンク

Postfix MTA: http://www.postfix.org/

OpenSSL: http://www.openssl.org/

Cyrus-SASL: http://asg.web.cmu.edu/sasl/

Postfix/TLS: http://www.aet.tu-cottbus.de/personen/jaenicke/postfix_tls/

この文書の元の場所:

http://www.falkotimme.com/howtos/postfix_smtp_auth_tls/

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。