メールサーバやWebサーバでSSL/TLSを利用する場合、SSL証明書が必要になります。
Let’s Encryptを利用すると、無料でSSL証明書を取得できます。
本記事では AlmaLinux を例に、Certbotを利用して証明書を取得する手順を紹介します。
前提条件
以下の条件を満たしている必要があります。
- ドメインを取得済み
- DNS設定済み
- サーバへSSH接続可能
- TCP 80番ポートが外部からアクセス可能
今回は以下のホスト名を例にします。
mail.example.com
DNS設定
事前にAレコードを設定します。
mail.example.com → サーバのグローバルIPアドレス
確認
dig mail.example.com
または
nslookup mail.example.com
Certbotのインストール
AlmaLinuxの場合
dnf install epel-release -y
dnf install certbot -y
確認
certbot --version
証明書取得
Webサーバを停止するか、80番ポートを使用していない状態で実行します。
certbot certonly --standalone -d mail.example.com
ApacheやNginxが起動している場合は、80番ポートが使用中のため --standalone は利用できません。
その場合は Webroot方式を利用します。
ApacheのDocumentRootが /var/www/html の場合
certbot certonly --webroot -w /var/www/html -d mail.example.com
Webroot方式であれば、ApacheやNginxを停止せずに証明書を取得できます。
証明書取得に成功すると、以下のようなメッセージが表示されます。
Successfully received certificate.
証明書保存場所
取得した証明書は以下に保存されます。
/etc/letsencrypt/live/mail.example.com/fullchain.pem
/etc/letsencrypt/live/mail.example.com/privkey.pem
確認
ls -l /etc/letsencrypt/live/mail.example.com/
証明書内容確認
openssl x509 -in /etc/letsencrypt/live/mail.example.com/fullchain.pem -text -noout
有効期限確認
openssl x509 -in /etc/letsencrypt/live/mail.example.com/fullchain.pem -noout -dates
自動更新確認
Let’s Encryptの証明書は90日間有効です。
Certbotは自動更新設定を作成します。
テスト実行
certbot renew --dry-run
成功例
Congratulations, all simulated renewals succeeded
apacheで利用する場合
/etc/httpd/conf.d/vhosts.conf
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Dovecotで利用する場合
/etc/dovecot/conf.d/10-ssl.conf
ssl = yes
ssl_cert = /etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = /etc/letsencrypt/live/mail.example.com/privkey.pem
反映
systemctl restart dovecot
Postfixで利用する場合
/etc/postfix/main.cf
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
smtpd_tls_security_level = may
反映
systemctl restart postfix
動作確認
HTTPS確認
openssl s_client -connect mail.example.com:443
IMAPS確認
openssl s_client -connect mail.example.com:993
POP3S確認
openssl s_client -connect mail.example.com:995
SMTPS確認
openssl s_client -connect mail.example.com:465
証明書情報が表示されれば設定完了です。
まとめ
Let’s Encryptを利用することで、無料でSSL証明書を取得できます。
取得した証明書は、PostfixやDovecotに設定することで、SMTP・POP3・IMAP通信を暗号化できます。
メールサーバを公開する場合は、SSL/TLSによる暗号化を必ず設定することを推奨します。

コメント