ここではLinuxアカウントがそのままメールアカウントになる運用方法を前提として記載してます。
この場合、POP/IMAPサーバへの接続はLinuxアカウントのパスワードになります。
&color(red){*};&size(10){pam経由でPOP/IMAP認証を行ってます};
***POP/IMAPの導入 [#q5ee8b63]
常にtelnetでメールを出すわけにはいかない。
PCから気軽にメールを出す、受け取るためにもPOP/IMAPサービスとして、ここではdovecotを採用します。
POPかIMAP。メールサーバのストレージに余裕があるのならIMAPかな。
IMAPだから、ではないが、postfixのメール格納方法を変更する
#code(diff){{
[root@c ~]# diff -u /etc/postfix/main.cf.170316 /etc/postfix/main.cf
--- /etc/postfix/main.cf.170316 2017-03-15 20:40:39.283125125 +0900
+++ /etc/postfix/main.cf 2017-03-16 05:39:50.444328609 +0900
@@ -424,7 +424,7 @@
# UNIX-style mailboxes are kept. The default setting depends on the
# system type.
#
-#mail_spool_directory = /var/mail
+mail_spool_directory = /var/mail/
#mail_spool_directory = /var/spool/mail
# The mailbox_command parameter specifies the optional external
[root@c ~]#
}}
もし/var/mailに各ユーザのメールがあるのなら、、変換ツールでmailbox形式からmaildir形式に変換します。&size(10){面倒なら削除..};
そしてpostfixを再起動します。
その後に、dovecotをインストールします
#code(nonumber){{
[root@c ~]# yum install dovecot
}}
そして、まずはメール保存先を指定します。
#code(diff){{
[root@c ~]# diff -u /etc/dovecot/conf.d/10-mail.conf.orig /etc/dovecot/conf.d/10-mail.conf
--- /etc/dovecot/conf.d/10-mail.conf.orig 2017-03-16 06:00:50.081678104 +0900
+++ /etc/dovecot/conf.d/10-mail.conf 2017-03-16 06:01:27.659086030 +0900
@@ -27,7 +27,7 @@
#
# <doc/wiki/MailLocation.txt>
#
-#mail_location =
+mail_location = maildir:/var/mail/%u
# If you need to set multiple mailbox locations or want to change default
# namespace settings, you can do it by defining namespace sections.
[root@c ~]#
}}
&size(10){mkdir /var/mail/<ユーザ> && chown uid:gid /var/mail/<ユーザ>};
次に、POP/IMAPへの接続認証方法を定める &size(10){SMTP認証ではありません};
#code(diff){{
[root@c ~]# diff -u /etc/dovecot/conf.d/10-auth.conf.orig /etc/dovecot/conf.d/10-auth.conf
--- /etc/dovecot/conf.d/10-auth.conf.orig 2017-03-16 06:04:55.536812493 +0900
+++ /etc/dovecot/conf.d/10-auth.conf 2017-03-16 15:37:07.021131667 +0900
@@ -7,7 +7,7 @@
# matches the local IP (ie. you're connecting from the same computer), the
# connection is considered secure and plaintext authentication is allowed.
# See also ssl=required setting.
-#disable_plaintext_auth = yes
+disable_plaintext_auth = no
# Authentication cache size (e.g. 10M). 0 means it's disabled. Note that
# bsdauth, PAM and vpopmail require cache_key to be set for caching to be used.
@@ -97,7 +97,7 @@
# plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
# gss-spnego
# NOTE: See also disable_plaintext_auth setting.
-auth_mechanisms = plain
+auth_mechanisms = plain login
##
## Password and user databases
[root@c ~]#
}}
#code(diff){{
[root@c ~]# diff -u /etc/dovecot/conf.d/10-ssl.conf.orig /etc/dovecot/conf.d/10-ssl.conf
--- /etc/dovecot/conf.d/10-ssl.conf.orig 2017-03-16 15:23:03.528155922 +0900
+++ /etc/dovecot/conf.d/10-ssl.conf 2017-03-16 15:23:08.851073692 +0900
@@ -5,7 +5,7 @@
# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
# disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
# plain imap and pop3 are still allowed for local connections
-ssl = required
+ssl = no
# PEM encoded X.509 SSL/TLS certificate and private key. They're opened before
# dropping root privileges, so keep the key file unreadable by anyone but
[root@c ~]#
}}
***メールクライアントとの接続 [#vac50bba]
&ref(2017y03m19d_190433046.png,nolink,noborder);
上記は、内部のネットワークからアクセスを前提にしているので通信の暗号化などは行っていない。
ThunderbirdでのPOP/IMAP設定は
&ref(2017y03m19d_184159401.png,nolink);
で行ける。&size(10){FWでPOP(110),IMAP(143)は閉じているので内部だけ利用可能};
SMTPは&color(magenta){/etc/postfix/main.cf};の&color(orangered){mynetworks};の値が
#code(nonumber){{
[root@c ~]# postconf |grep ^mynetworks
mynetworks = 127.0.0.0/8 192.168.0.0/24 [::1]/128 [fe80::]/64
mynetworks_style = subnet
[root@c ~]#
}}
なのでサブドメインに所属しているマシンはSMTP認証なしでローカルのSMTPマシンに投げれる。
そのためThunderbirdのSMTP設定部分は
&ref(2017y03m19d_191524818.png,nolink);
で行ける
***メールクライアントを外部で使いたい [#ye7dbf8a]
&size(10){メールの送信を外部から行いたい場合は、[[mail/smtp-auth]]を参照};
外部から接続する場合、メールクライアントとメールサーバ間の通信の暗号化くらいは行ったほうがいいみたい。
そのためには証明書が必要で、dovecotパッケージにはそのツールが用意されている
-/usr/libexec/dovecot/mkcert.sh
-/etc/pki/dovecot/dovecot-openssl.cnf
dovecot-openssl.cnfの内容を自サイトに合わせて調整して、mkcert.shを実行すれば証明書は作成される。
#code(diff,nonumber){{
[root@c ~]# diff -u /etc/pki/dovecot/dovecot-openssl.cnf.orig /etc/pki/dovecot/dovecot-openssl.cnf
--- /etc/pki/dovecot/dovecot-openssl.cnf.orig 2013-03-14 22:28:31.000000000 +0900
+++ /etc/pki/dovecot/dovecot-openssl.cnf 2017-03-29 10:35:28.395391404 +0900
@@ -7,25 +7,25 @@
[ req_dn ]
# country (2 letter code)
-#C=FI
+C=JP
# State or Province Name (full name)
-#ST=
+ST=Tokyo
# Locality Name (eg. city)
-#L=Helsinki
+L=Chuo
# Organization (eg. company)
-#O=Dovecot
+O=Chaperone
# Organizational Unit Name (eg. section)
OU=IMAP server
# Common Name (*.example.com is also possible)
-CN=imap.example.com
+CN=web.chaperone.jp
# E-mail contact
-emailAddress=postmaster@example.com
+emailAddress=postmaster@chaperone.jp
[ cert_type ]
nsCertType = server
[root@c ~]#
}}
と修正して、mkcert.shを実行する
#code(nonumber){{
[root@c ~]# rm -rf /etc/pki/dovecot/certs/dovecot.pem <-- dovecotパッケージに同封された証明書(imap.example.com向け)
[root@c ~]# rm -rf /etc/pki/dovecot/private/dovecot.pem <-- dovecotパッケージに同封された秘密鍵
[root@c ~]# /usr/libexec/dovecot/mkcert.sh
Generating a 1024 bit RSA private key
.......++++++
.................................++++++
writing new private key to '/etc/pki/dovecot/private/dovecot.pem'
-----
subject= /C=JP/ST=Tokyo/L=Chuo/O=Chaperone/OU=IMAP server/CN=web.chaperone.jp/emailAddress=postmaster@chaperone.jp
SHA1 Fingerprint=36:7A:C6:00:5A:47:04:9D:A9:3B:2B:11:93:4D:52:37:86:D7:29:95
[root@c ~]#
}}
これで、証明書(/etc/pki/dovecot/certs/dovecot.pem)と秘密鍵(/etc/pki/dovecot/private/dovecot.pem)が作成されました。
証明書の確認は
#code(nonumber){{
[root@c ~]# openssl x509 -in /etc/pki/dovecot/certs/dovecot.pem -text
}}
にて可能です。
次に、/etc/dovecot/conf.d/10-ssl.confの内容を修正して、ssl通信を有効にさせ、dovecotを再起動します
#code(diff,nonumber){{
[root@c ~]# diff -u /etc/dovecot/conf.d/10-ssl.conf.170329 /etc/dovecot/conf.d/10-ssl.conf
--- /etc/dovecot/conf.d/10-ssl.conf.170329 2017-03-29 10:51:30.433669406 +0900
+++ /etc/dovecot/conf.d/10-ssl.conf 2017-03-29 10:51:44.312457760 +0900
@@ -5,7 +5,7 @@
# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
# disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
# plain imap and pop3 are still allowed for local connections
-ssl = no
+ssl = required
# PEM encoded X.509 SSL/TLS certificate and private key. They're opened before
# dropping root privileges, so keep the key file unreadable by anyone but
[root@c ~]#
}}
#code(nonumber){{
[root@c ~]# systemctl restart dovecot
}}
この後、ThunderbirdでのPOP/IMAP設定を下記のように設定しなおす。
&ref(2017y03m29d_110136110.png,nolink);
これでアクセスしようとすると、下記警告が表示される。
&ref(2017y03m29d_110455549.png,nolink);
例外を許諾すると、メールクライアントにこのメールサーバの証明書が登録される。
本来なら、正式な証明書を貰うべきかと思う。[[certbot]]を使うのも手なのかもしれない
この後、ルータを調整して外部からメールサーバへのアクセスを許可させる。
こちらではポートマッピングで993ポートをローカルメールサーバに結ばせている。