10.11. SSL による SMTP の暗号化

SMTP サービスにおいても SSL を用いて通信経路を暗号化することが可能です。

SSL により暗号化された SMTP サーバーを構築するには、openssl コマンドを実行して、/var/ssl/certs ディレクトリに鍵ファイル smtp.pem を作成します。

鍵を生成するために以下のコマンドを実行します。openssl コマンドは、幾つかの質問をしてきますので、入力してください。

ティップ

POP3/IMAP4 用に作成した鍵ファイルのファイル名を変更して利用することも可能です。

# cd /var/ssl/certs
# openssl req -new -x509 -nodes -out smtp.pem -keyout smtp.pem
Generating a 1024 bit RSA private key
...................................................++++++
................++++++
writing new private key to 'imapsd.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:Tokyo
Locality Name (eg, city) []:Shibuya
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Turbolinux
Organizational Unit Name (eg, section) []:Doc
Common Name (eg, YOUR name) []:smtp.example.com
Email Address []:doc@turbolinux.co.jp

作成後は、鍵ファイルが他のユーザーから参照されないようにファイルのパーミッションを変更します。

# chmod 600 smtp.pem

/etc/postfix/main.cf ファイルを以下の例のように編集します。

  smtpd_use_tls = yes
  smtpd_tls_cert_file = /var/ssl/certs/smtp.pem
  smtpd_tls_key_file = $smtpd_tls_cert_file

SMTPS を使用する場合には、/etc/postfix/master.cf ファイルを以下の例のように編集します。Turbolinux 11 Server のデフォルトではコメント行として記述されています。コメント記号(#)を削除して有効にしてください。

smtps     inet  n       -       n       -       -       smtpd
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

Postfix を再起動して設定を反映します。

# /etc/init.d/postfix restart