2012年7月16日月曜日

[RESOLVED] warning: not set-gid or not owner+group+world executable:

postfix起動時に以下のメッセージが表示されます。
Jul 16 11:10:25 v103-3-189-170 postfix/postfix-script[3588]: warning: not set-gid or not owner+group+world executable: /usr/sbin/postqueue
Jul 16 11:10:25 v103-3-189-170 postfix/postfix-script[3589]: warning: not set-gid or not owner+group+world executable: /usr/sbin/postdrop
それぞれのファイルのパーミッションは以下の通りです。
-rwxr-xr-x 1 root maildrop 15064 May 10 18:44 postdrop
-rwxr-xr-x 1 root maildrop 15016 May 10 18:44 postqueue
パーミッションを以下の通り変更します。
# cd /usr/sbin
# chmod g+s postdrop postqueue
# ls -l postqueue postdrop 
-rwxr-sr-x 1 root maildrop 15064 May 10 18:44 postdrop
-rwxr-sr-x 1 root maildrop 15016 May 10 18:44 postqueue

[RESOLVED] warning: not owned by group maildrop:

メッセージの内容は以下の通り。
Jul 16 10:59:28 v103-3-189-170 postfix/postfix-script[3316]: warning: not owned by group maildrop: /usr/sbin/postqueue
Jul 16 10:59:28 v103-3-189-170 postfix/postfix-script[3317]: warning: not owned by group maildrop: /usr/sbin/postdrop
この時の各ファイルのオーナーは次の通り。
-rwxr-xr-x 1 root root 15064 May 10 18:44 postdrop
-rwxr-xr-x 1 root root 15016 May 10 18:44 postqueue
グループをmaildropに変更します。
# chgrp maildrop postqueue postdrop
# ls -l
-rwxr-xr-x 1 root maildrop 15064 May 10 18:44 postdrop
-rwxr-xr-x 1 root maildrop 15016 May 10 18:44 postqueue

openSUSE12.1 メールサーバー インストール postfix dovecot

openSUSE12.1に、postfixとdovecotをインストールして、メールサーバーを構築します。
# zypper install --no-recommends postfix dovecot12
Loading repository data...
Reading installed packages...
'postfix' is already installed.
No update candidate for 'postfix-2.8.8-3.13.1.x86_64'. The highest available version is already installed.
Resolving package dependencies...

The following NEW package is going to be installed:
  dovecot12 

The following packages are recommended, but will not be installed:
  dovecot12-backend-mysql dovecot12-backend-pgsql dovecot12-backend-sqlite 

1 new package to install.
Overall download size: 2.6 MiB. After the operation, additional 14.4 MiB will 
be used.
Continue? [y/n/?] (y): y
Retrieving package dovecot12-1.2.17-7.1.3.x86_64 (1/1), 2.6 MiB (14.4 MiB unpacked)
Retrieving: dovecot12-1.2.17-7.1.3.x86_64.rpm [done]
Installing: dovecot12-1.2.17-7.1.3 [done]
postfixはインストールされていました。 今回は次のようなメールサーバーを構築します。
  • SASL認証はdovecotで行う
  • virtual mailboxを使う
  • SSLによる暗号化
  • IMAPを使う
postfixがdovecot SASLをサポートしていることを確認します。
# postconf -a
cyrus
dovecot
SSLの自己証明書と秘密鍵を作ります。
# cd /etc/ssl/private
# openssl req -new -x509 -nodes -days 3650 -out mail.crt -keyout mail.key
Generating a 1024 bit RSA private key
.....++++++
...........................................++++++
writing new private key to 'mail.key'
-----
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]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:mail.lool.jp  
Email Address []:

# chmod 600 mail.key
次にvirtual mailbox用に、ユーザーとグループを作成します。
# groupadd -g 1001 vmail
# useradd -u 1001 -g 1001 -d /var/spool/vmail -r -s /sbin/nologin vmail
virtual mailboxディレクトリを作成します。
# mkdir /var/spool/vmail
# chown vmail.vmail /var/spool/vmail
# chmod 700 /var/spool/vmail
/etc/postfix/main.cfを編集します。
setgid_group = maildrop
daemon_directory = /usr/lib/postfix

myhostname = mail.lool.jp
mydomain = lool.jp
myorigin = $mydomain
mydestination = $myhostname localhost.$mydomain localhost
smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_unauth_destination,
        permit_auth_destination,
        reject

debug_peer_level = 3

home_mailbox = Maildir/

virtual_alias_maps = hash:/etc/postfix/virtual
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_gid_maps = static:1001
virtual_uid_maps = static:1001
virtual_mailbox_base = /var/spool/vmail
virtual_mailbox_domains = lool.jp

smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/dovecot-auth
/etc/postfix/vmailboxにvirtual mailboxを定義します。
mascotpark@lool.jp mascotpark/Maildir/
# cd /etc/postfix
# postmap vmailbox
/etc/postfix/master.cfを編集します。
smtp      inet  n       -       n       -       -       smtpd
submission inet n       -       n       -       -       smtpd
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
次に/etc/dovecot/dovecot.confを編集します。
protocols = imap imaps

   protocol imap {
     listen = *:143
     ssl_listen = *:993
   }
listen = *

disable_plaintext_auth = yes

ssl = yes
ssl_cert_file = /etc/ssl/private/mail.crt
ssl_key_file = /etc/ssl/private/mail.key
verbose_ssl = yes

mail_location = maildir:/var/spool/vmail/%u/Maildir

mail_uid = 1001
mail_gid = 1001

mail_debug = yes
lock_method = fcntl

protocol imap {
  mail_plugin_dir = /usr/lib64/dovecot/modules/imap
}

auth_username_format = %Ln

auth default {
  mechanisms = cram-md5 login plain
  passdb passwd-file {
    args = scheme=CRAM-MD5 username_format=%u /etc/dovecot/passwd
  }
  user = root
  socket listen {
    master {
      path = /var/run/dovecot/auth-master
      mode = 0600
      user = postfix
      group = postfix
    }
    client {
      path = /var/spool/postfix/private/dovecot-auth
      mode = 0660
      user = postfix
      group = postfix
    }
  }
}

dict {
}

plugin {
}
/etc/dovecot/passwdファイルを作ります。
mascotpark:{CRAM-MD5}477934589a58e54b516c742aff2e8a77019df50f3b33f134385b875047370666
サービスを再起動します。
# systemctl restart postfix.service
# systemctl restart dovecot.service
Firewallを設定します。 smtpとdovecotで使用するポート番号を設定します。 /etc/sysconfig/SuSEfirewall2.d/services/smtp
TCP="25 465 587"
/etc/sysconfig/SuSEfirewall2.d/services/dovecot
TCP="imap imaps pop3 pop3s sieve 4190"
/etc/sysconfig/SuSEfirewall2を編集し、サービスを再起動します。
FW_CONFIGURATIONS_EXT="sshd smtp dovecot"
# /sbin/SuSEfirewall2 stop
SuSEfirewall2: Firewall rules unloaded.
# /sbin/SuSEfirewall2 start
SuSEfirewall2: Setting up rules from /etc/sysconfig/SuSEfirewall2 ...
SuSEfirewall2: using default zone 'ext' for interface eth0
SuSEfirewall2: Firewall rules successfully set
telnetを使って動作を確認します。
# telnet localhost 25
EHLO localhost
250-mail.lool.jp
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
MAIL FROM:root
250 2.1.0 Ok
RCPT TO:mascotpark@lool.jp
250 2.1.5 Ok
DATA
354 End data with .
TEST
.
250 2.0.0 Ok: queued as 6EC272003DA
quit
221 2.0.0 Bye
Connection closed by foreign host.
# telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE STARTTLS AUTH=CRAM-MD5 AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
x LOGIN mascotpark@lool.jp password
x OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT IDLE CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS] Logged in
x LOGOUT
* BYE Logging out
x OK Logout completed.
Connection closed by foreign host.

2012年7月10日火曜日

SUSE sshdのポートを変更したのでFirewallの設定を変える

sshdのポートを20から2022に変更したので、それに合わせてFirewallのポートも20から2022に変更します。 /etc/sysconfig/SuSEfirewall2.d/servicesディレクトリの下に、サービス名のファイル名があります。 今回は、sshdですので、その内容を以下に変更します。
## Name: Secure Shell Server
## Description: Open ports for Secure Shell Server

# space separated list of allowed TCP ports
#TCP="ssh"
TCP=2022
設定の変更を反映する方法はまだ分かっていません。。。リブートしました。

2012年7月9日月曜日

SUSE ホスト名の変更 固定IPアドレス デフォルトゲートウェイ設定 DNS設定

ホスト名を変更するには、/etc/HOSTNAMEファイルを編集します。
myhostname
/etc/sysconfig/network/ifcfg-eth0を編集して、ネットワークを設定します。
BOOTPROTO='static'
BROADCAST='103.3.189.255'
ETHTOOL_OPTIONS=''
IPADDR='103.3.189.170'
MTU=''
NAME='Ethernet Card 0'
NETMASK='255.255.255.0'
NETWORK='103.3.189.0'
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'
デフォルトゲートウェイを設定します。 /etc/sysconfig/network/routesファイルを作成します。
default 103.3.189.1 - -
/etc/resolv.confを編集して、DNSサーバーを設定します。/etc/resolv.confを手動で編集する際には、/etc/sysconfig/network/configファイルを編集します。
NETCONFIG_DNS_POLICY=""
search myvps.jp
nameserver 210.157.1.170
nameserver 210.172.133.178

お名前.com VPSにopenSUSEをインストール

お名前.comのVPS(2GB)を借りたので、openSUSEをインストールしてみました。

まずはOS Imageをダウンロードします。
software.opensuse.org: openSUSE 12.1 のダウンロード
次にダウンロードしたISOイメージをアップロードします。そのために、コントロールパネルの画面から、ssh private keyをダウンロードします。ページの下の方にあります。

接続先サーバー名、ユーザー名、ダウンロードした公開鍵ファイルを使って、SFTPで接続します。接続したらimagesディレクトリの下に、ダウンロードしたISOイメージファイルをアップロードします。
次にOS再インストールのタブを選択して、OSにアップロードしたopenSUSEを選択します。パーティションはお好みで。

実行すると、サーバーリストが表示されますので、IPアドレスと初期ホスト名をメモしておきます。起動をクリックして、VMをブートします。


installationを選択します。
言語とキーボードレイアウトを日本語に設定して、次へ。

新規インストールと手動設定を選んで、次へ。

ハードウェアの時刻はUTCに設定のチェックを外します。

私はサーバー用途でインストールしますので、最小限のサーバ(テキストモード)を選びます。

パーティションを任意に設定して、次へ。

ユーザー名とパスワードなどこちらもお好みで。

インストール設定を確認します。最後のsshを有効にしました。

問題がなければインストールをGO!

ホスト名とドメイン名を設定しますが、とりあえずデフォルトのまま進みます。

デフォルトのままでもいいですが、IPv6を無効にしてから次に進みます。

インターネットへの接続テストはお好みで。

エラーが表示されてもあまり気にせず前に進みます。

オンライン更新を実行するのまま、次に進みます。

了解して次へ進みます。

修正のダウンロードとインストールが完了したら次へ進みます。

途中おかしくなったら再起動します。次の画面が表示されたらインストールは終わりです。

2012年7月8日日曜日

postfix + dovecot on SL6

postfixの設定

# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
home_mailbox = Maildir/
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
local_recipient_maps = proxy:unix:passwd.byname $alias_maps $virtual_mailbox_maps
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost
myhostname = mail.lumiukko.jp
mynetworks = 49.212.129.72
mynetworks_style = host
myorigin = $myhostname
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relay_domains = $mydestination
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/dovecot-auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/pki/tls/certs/mail.crt
smtpd_tls_key_file = /etc/pki/tls/certs/mail.key
smtpd_use_tls = yes
unknown_local_recipient_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_gid_maps = static:502
virtual_mailbox_base = /var/spool/vmail
virtual_mailbox_domains = lumiukko.jp
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_uid_maps = static:502
/etc/postfix/master.cfの内容
smtp      inet  n       -       n       -       -       smtpd
submission inet n       -       n       -       -       smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
#smtps     inet  n       -       n       -       -       smtpd
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
/etc/postfix/vmailboxの内容
nordenlife@lumiukko.jp lumiukko.jp/nordenlife/Maildir/

dovecotの設定

# doveconf -n
# 2.0.9: /etc/dovecot/dovecot.conf
# OS: Linux 2.6.32-220.7.1.el6.x86_64 x86_64 Scientific Linux release 6.2 (Carbon) 
auth_mechanisms = cram-md5 login
auth_username_format = %Lu
auth_verbose = yes
listen = *
mail_debug = yes
mail_location = maildir:~/Maildir
mbox_write_locks = fcntl
passdb {
  args = scheme=CRAM-MD5 username_format=%u /etc/dovecot/passwd
  driver = passwd-file
}
protocols = imap
service auth {
  unix_listener /var/spool/postfix/private/dovecot-auth {
    group = postfix
    mode = 0600
    user = postfix
  }
}
ssl = required
ssl_cert = </etc/pki/tls/certs/mail.crt
ssl_key = </etc/pki/tls/certs/mail.key
userdb {
  args = uid=vmail gid=vmail home=/var/spool/vmail/%d/%n
  driver = static
}
/etc/dovecot/passwdの内容
nordenlife@lumiukko.jp:{CRAM-MD5}c68d3329d0db55548a14e9d7

2012年7月7日土曜日

[RESOLVED] Recipient address rejected: User unknown in local recipient tabl

postfix + dovecotでメールサーバーを構築中ですが、以下のメッセージが表示されうまくメールが送信できません。 ユーザー認証は、dovecot側でバーチャルユーザーを使っています。
# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.lumiukko.jp ESMTP Postfix
HELO mail.lumiukko.jp
250 mail.lumiukko.jp
MAIL FROM:root
250 2.1.0 Ok
RCPT TO:nordenlife@lumiukko.jp
550 5.1.1 : Recipient address rejected: User unknown in local recipient table
上記のテストで、/var/log/maillogに出力されるエラーメッセージは以下の通り。
Jul  7 23:01:17 www4298uf postfix/smtpd[19280]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 550 5.1.1 : Recipient address rejected: User unknown in local recipient table; from= to= proto=SMTP helo=
dovecotにimapで接続する際の認証はうまく行ってる気がするのですが。。。
# telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=CRAM-MD5 AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
x LOGIN nordenlife@lumiukko.jp password
x OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS] Logged in
x LOGOUT
* BYE Logging out
x OK Logout completed.
Connection closed by foreign host.
postfixの認証を試してみるとうまく行きます。うーん。 ログイン認証はbase64でエンコードする必要があります。
# echo -n "nordenlife@lumiukko.jp" | base64
bm9yZGVubGlmZUBsdW1pdWtrby5qcA==
# echo -n "password" | base64
cGFzc3dvcmQ=
[root@www4298uf ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.lumiukko.jp ESMTP Postfix
AUTH LOGIN
334 VXNlcm5hbWU6
bm9yZGVubGlmZUBsdW1pdWtrby5qcA==
334 UGFzc3dvcmQ6
cGFzc3dvcmQ=
235 2.7.0 Authentication successful
QUIT
221 2.0.0 Bye
Connection closed by foreign host.

原因判明

local_recipient_mapsを設定していなかったことが原因でした。 /etc/postfix/main.cf
local_recipient_maps = proxy:unix:passwd.byname $alias_maps $virtual_mailbox_maps
alias_maps = hash:/etc/aliases
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
ちなみに、/etc/postfix/vmailboxの内容は以下になっています。
nordenlife@lumiukko.jp lumiukko.jp/nordenlife/Maildir/