ConoHa VPS の Ubuntu 24.04 で Dovecot と Postfix を設定する

ConoHa VPS Ubuntu 24.04 で Dovecot と Postfix の設定を行った。

Dovecot

apt install dovecot-imapd

~/Maildir を使うように /etc/dovecot/conf.d/10-mail.conf の mail_location の行を次のように編集する。

mail_location = maildir:~/Maildir

/etc/dovecot/conf.d/10-auth.conf を編集して、次のようにする。

disable_plaintext_auth = yes
auth_mechanisms = plain login

/etc/dovecot/conf.d/10-mail.conf では標準で

mail_privileged_group = mail

となっていたので

usermod -aG mail [USERNAME]

で使用するユーザを mail グループに登録する。 証明書の設定を行う。すでに、Let’s Encrypt で証明書を取得してあるので、それを利用する。

certbot certificates

でファイルのパスを確認し /etc/dovecot/conf.d/10-ssl.conf に

ssl_cert = </etc/letsencrypt/live/example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/example.com/privkey.pem

などと書く。

systemctl restart dovecot.service

で設定を読み込んだら、動作を確認する。

systemctl status dovecot.service
ss -lntp
openssl s_client -connect example.com:993 -servername example.com -showcerts 

ポートを明ける。

ufw allow 993

ConoHa VPS のポートの設定も確認しておく。

Postfix

/etc/postfix/master.cf に以下を加える。

submission inet n       -       y       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

/etc/postfix/main.cf を次のように編集する。

smtpd_tls_cert_file = /etc/letsencrypt/live/example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/example.com/privkey.pem
smtpd_tls_security_level = may
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination

/etc/dovecot/conf.d/10-master.conf の service auth を次のようにする。

service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix
  }
}

ポートを開ける。

ufw allow 587

最後に dovecot と postfix を再起動する。

postfix check
systemctl restart dovecot
systemctl restart postfix

Tags of current page

, , ,