サーバー設定 · 4 min read · Oct 09, 2025
完璧なサーバー - Ubuntu Jaunty Jackalope (Ubuntu 9.04) [ISPConfig 2] - ページ 5
15 Postfix With SMTP-AUTH And TLS
PostfixをSMTP-AUTHおよびTLSでインストールするには、以下の手順を実行します:
aptitude install postfix libsasl2-2 sasl2-bin libsasl2-modules procmail2つの質問が表示されます。次のように回答してください:
一般的なメール構成のタイプ: <– インターネットサイト
システムメール名: <– server1.example.com
次に、実行します。
dpkg-reconfigure postfix再度、いくつかの質問が表示されます:
一般的なメール構成のタイプ: <– インターネットサイト
システムメール名: <– server1.example.com
ルートおよびポストマスターのメール受信者: <– [空白]
受け入れる他の宛先(なしの場合は空白): <– server1.example.com, localhost.example.com, localhost.localdomain, localhost
メールキューの同期更新を強制しますか? <– いいえ
ローカルネットワーク: <– 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
ローカル配信にprocmailを使用しますか? <– はい
メールボックスサイズ制限(バイト): <– 0
ローカルアドレス拡張文字: <– +
使用するインターネットプロトコル: <– すべて
次に、これを実行します:
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_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'inet_interfaces = all'
echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf
echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.confその後、TLS用の証明書を作成します:
mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csropenssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crtopenssl rsa -in smtpd.key -out smtpd.key.unencryptedmv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650次に、PostfixをTLS用に設定します(myhostnameに正しいホスト名を使用していることを確認してください):
postconf -e 'myhostname = server1.example.com'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'ファイル/etc/postfix/main.cfは次のようになります:
cat /etc/postfix/main.cf| # See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no # TLS parameters smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key smtpd_use_tls = yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. myhostname = server1.example.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = server1.example.com, localhost.example.com, localhost.localdomain, localhost relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = all smtpd_sasl_local_domain = smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous broken_sasl_auth_clients = yes smtpd_sasl_authenticated_header = yes smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination smtpd_tls_auth_only = no smtp_use_tls = yes smtp_tls_note_starttls_offer = yes smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem smtpd_tls_loglevel = 1 smtpd_tls_received_header = yes smtpd_tls_session_cache_timeout = 3600s tls_random_source = dev:/dev/urandom |
認証はsaslauthdによって行われます。正しく動作させるためにいくつかの変更を行う必要があります。Postfixは/var/spool/postfix内でchrootされて実行されるため、次のことを行う必要があります:
mkdir -p /var/spool/postfix/var/run/saslauthd次に、/etc/default/saslauthdを編集してsaslauthdを有効にします。STARTをyesに設定し、OPTIONS=”-c -m /var/run/saslauthd”の行をOPTIONS=”-c -m /var/spool/postfix/var/run/saslauthd -r”に変更します:
vi /etc/default/saslauthd| # Settings for saslauthd daemon # Please read /usr/share/doc/sasl2-bin/README.Debian for details. # # Should saslauthd run automatically on startup? (default: no) START=yes # Description of this saslauthd instance. Recommended. # (suggestion: SASL Authentication Daemon) DESC="SASL Authentication Daemon" # Short name of this saslauthd instance. Strongly recommended. # (suggestion: saslauthd) NAME="saslauthd" # Which authentication mechanisms should saslauthd use? (default: pam) # # Available options in this Debian package: # getpwent -- use the getpwent() library function # kerberos5 -- use Kerberos 5 # pam -- use PAM # rimap -- use a remote IMAP server # shadow -- use the local shadow password file # sasldb -- use the local sasldb database file # ldap -- use LDAP (configuration is in /etc/saslauthd.conf) # # Only one option may be used at a time. See the saslauthd man page # for more information. # # Example: MECHANISMS="pam" MECHANISMS="pam" # Additional options for this mechanism. (default: none) # See the saslauthd man page for information about mech-specific options. MECH_OPTIONS="" # How many saslauthd processes should we run? (default: 5) # A value of 0 will fork a new process for each connection. THREADS=5 # Other options (default: -c -m /var/run/saslauthd) # Note: You MUST specify the -m option or saslauthd won't run! # # WARNING: DO NOT SPECIFY THE -d OPTION. # The -d option will cause saslauthd to run in the foreground instead of as # a daemon. This will PREVENT YOUR SYSTEM FROM BOOTING PROPERLY. If you wish # to run saslauthd in debug mode, please run it by hand to be safe. # # See /usr/share/doc/sasl2-bin/README.Debian for Debian-specific information. # See the saslauthd man page and the output of 'saslauthd -h' for general # information about these options. # # Example for postfix users: "-c -m /var/spool/postfix/var/run/saslauthd" #OPTIONS="-c -m /var/run/saslauthd" OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r" |
次に、postfixユーザーをsaslグループに追加します(これにより、Postfixがsaslauthdにアクセスする権限を持つことが保証されます):
adduser postfix sasl次に、Postfixを再起動し、saslauthdを開始します:
/etc/init.d/postfix restart
/etc/init.d/saslauthd startSMTP-AUTHとTLSが正しく機能しているかどうかを確認するには、次のコマンドを実行します:
telnet localhost 25Postfixメールサーバーへの接続が確立されたら、次のように入力します。
ehlo localhost次の行が表示される場合:
250-STARTTLSおよび
250-AUTH LOGIN PLAINすべてが正常です。
私のシステムでの出力は次のようになります:
root@server1:/etc/postfix/ssl# telnet localhost 25
Trying ::1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 server1.example.com ESMTP Postfix (Ubuntu)
ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
root@server1:/etc/postfix/ssl#quitと入力してシステムのシェルに戻ります。
16 Courier-IMAP/Courier-POP3
Courier-IMAP/Courier-IMAP-SSL(ポート993のIMAP用)およびCourier-POP3/Courier-POP3-SSL(ポート995のPOP3用)をインストールするには、次のコマンドを実行します:
aptitude install courier-authdaemon courier-base courier-imap courier-imap-ssl courier-pop courier-pop-ssl courier-ssl gamin libgamin0 libglib2.0-02つの質問が表示されます:
ウェブベースの管理用にディレクトリを作成しますか? <– いいえ
SSL証明書が必要ですか <– はい
インストール中に、IMAP-SSLおよびPOP3-SSL用のSSL証明書がホスト名localhostで作成されます。これを正しいホスト名(このチュートリアルではserver1.example.com)に変更するには、証明書を削除します…
cd /etc/courier
rm -f /etc/courier/imapd.pem
rm -f /etc/courier/pop3d.pem… 次に、以下の2つのファイルを修正します。CN=localhostをCN=server1.example.comに置き換えます(必要に応じて他の値も変更できます):
vi /etc/courier/imapd.cnf| [...] CN=server1.example.com [...] |
vi /etc/courier/pop3d.cnf| [...] CN=server1.example.com [...] |
次に、証明書を再作成します…
mkimapdcert
mkpop3dcert… そして、Courier-IMAP-SSLおよびCourier-POP3-SSLを再起動します:
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop-ssl restartISPConfigを使用しない場合は、PostfixをユーザーのMaildir*にメールを配信するように構成します:
postconf -e 'home_mailbox = Maildir/'
postconf -e 'mailbox_command ='
/etc/init.d/postfix restart*注意: ISPConfigをシステムで使用する予定がある場合は、これを行う必要はありません。ISPConfigはprocmailレシピを使用して必要な構成を行います。ただし、ISPConfigのWebインターフェースで管理 -> サーバー -> 設定 -> Eメールの下でMaildirを有効にすることを確認してください。
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。