Postfix

Postfix 는 우분투에서 기본 설정된 Mail Transfer Agent (MTA) 입니다. 이것은 빠르고 관리와 보안을 하기가 수월 합니다. 그리고 MTA 인 sendmail 과 호환이 됩니다. 이 영역은 postfix 를 어떻게 설치하고 설정하는 지를 설명 합니다. 또한 그것을 보안 연결을 (안전하게 이메일을 보내기 위한) 사용하는 SMTP 서버로서 어떻게 만드는 지를 설명 합니다.

설치

postfix를 SMTP-AUTH와 Transport Layer Security (TLS)과 함께 설치하기 위하여, 다음의 명령을 실행 합니다:

sudo apt-get install postfix

설치 과정 중에 물어보는 질문에 간단히 엔터키를 누르고, 설정은 다음 단계에서 보다 자세히 마쳐지게 됩니다.

기본적인 설정

postfix 를 설정하기 위하여, 다음 명령을 실행 합니다:

sudo dpkg-reconfigure postfix

사용자 인터페이스가 보여지게 됩니다. 각 화면에서, 다음의 값들을 선택 합니다:

  • Ok

  • Internet Site

  • NONE

  • mail.example.com

  • mail.example.com, localhost.localdomain, localhost

  • No

  • 127.0.0.0/8

  • Yes

  • 0

  • +

  • all

[참고]

mail.example.com 는 여러분의 메일 서버 호스트 이름으로 대체 합니다.

Now is a good time to decide which mailbox format you want to use. By default Postifx will use mbox for the mailbox format. Rather than editing the configuration file directly, you can use the postconf command to configure all postfix parameters. The configuration parameters will be stored in /etc/postfix/main.cf file. Later if you wish to re-configure a particular parameter, you can either run the command or change it manually in the file.

To configure the mailbox format for Maildir:

sudo postconf -e 'home_mailbox = Maildir/'
[참고]

This will place new mail in /home/username/Maildir so you'll need to configure your Mail Delivery Agent to use the same path.

SMTP 인증

The next steps are to configure postfix to use SASL for SMTP AUTH.

  1. Configure Postfix to do SMTP AUTH using SASL (saslauthd):

    sudo postconf -e 'smtpd_sasl_local_domain ='
    sudo postconf -e 'smtpd_sasl_auth_enable = yes'
    sudo postconf -e 'smtpd_sasl_security_options = noanonymous'
    sudo postconf -e 'broken_sasl_auth_clients = yes'
    sudo postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
    sudo postconf -e 'inet_interfaces = all'
    

    Open the /etc/postfix/sasl/smtpd.conf file and add the following lines to end of the file:

    pwcheck_method: saslauthd
    mech_list: plain login
    

  2. 다음으로 TLS를 위한 디지털 인증서를 설정합니다. 질문에 대해 다음 지시에 따라 적절히 답하세요.

    openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
    chmod 600 smtpd.key
    openssl req -new -key smtpd.key -out smtpd.csr
    openssl x509 -req -days 365 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
    openssl rsa -in smtpd.key -out smtpd.key.unencrypted
    mv -f smtpd.key.unencrypted smtpd.key
    openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
    sudo mv smtpd.key /etc/ssl/private/
    sudo mv smtpd.crt /etc/ssl/certs/
    sudo mv cakey.pem /etc/ssl/private/
    sudo mv cacert.pem /etc/ssl/certs/
    
    [참고]

    여러분은 인증 기관(certificate authority)에서 디지털 인증서를 받을 수 있습니다. 혹은 여러분 스스로 인증서를 생성할 수도 있습니다. 자세한 사항은 스스로 서명한 인증서 만들기 부분을 살펴보십시오.

  3. Configure Postfix to do TLS encryption for both incoming and outgoing mail:

    sudo postconf -e 'smtpd_tls_auth_only = no'
    sudo postconf -e 'smtp_use_tls = yes'
    sudo postconf -e 'smtpd_use_tls = yes'
    sudo postconf -e 'smtp_tls_note_starttls_offer = yes'
    sudo postconf -e 'smtpd_tls_key_file = /etc/ssl/private/smtpd.key'
    sudo postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt'
    sudo postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem'
    sudo postconf -e 'smtpd_tls_loglevel = 1'
    sudo postconf -e 'smtpd_tls_received_header = yes'
    sudo postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
    sudo postconf -e 'tls_random_source = dev:/dev/urandom'
    sudo postconf -e 'myhostname = mail.example.com'
    

  4. Turn off the chroot operation for SMTP server. Locate for the following line in /etc/postfix/master.cf file:

    smtp      inet  n       -       -       -       -       smtpd
    

    and modify it as follows:

    smtp      inet  n       -       n       -       -       smtpd
    
[참고]

명령을 모두 실행하고 나면 postfix를 위한 SMTP AUTH의 설정이 모두 끝납니다. postfix에서 이어서 TLS에서 사용할 인증서를 직접 서명하여 설정합니다.

이때 /etc/postfix/main.cfthis이 같아보여야 합니다.

Postfix의 초기 설정이 이제 끝났습니다. Postfix 데몬을 시작하려면

          
            sudo /etc/init.d/postfix start
          
        

을 실행하십시오. 이제 postfix 데몬이 무사히 설치되었으며, 설정이 끝나고 이제 실행중입니다. PostfixRFC2554에서 정의한 SMTP AUTH를 지원하며, SASL를 따르고 있습니다. 하지만 SMTP를 사용기 위해서는 SASL 인증도 설정해야 합니다.

SASL 설정하기

The libsasl2-2, sasl2-bin and libsasl2-modules are necessary to enable SMTP AUTH using SASL. You can install these applications if you have not installed them already.

sudo apt-get install libsasl2-2 sasl2-bin

A few changes are necessary to make it work properly. Because Postfix runs chrooted in /var/spool/postfix, SASL needs to be configured to run in the false root (/var/run/saslauthd becomes /var/spool/postfix/var/run/saslauthd):

sudo mkdir -p /var/spool/postfix/var/run/saslauthd
sudo rm -rf /var/run/saslauthd

saslauthd을 작동시키려면, /etc/default/saslauthd 을 편집하기 위하여 열고, START 변수를 변경하거나 추가 합니다. saslauthd 이 가짜 root 환경에서 실행되도록 설정하기 위해서는, PWDIR, PIDFILE과 PARAMS 변수를 더합니다. 마지막으로, MECHANISMS 변수를 여러분이 좋아하는 곳으로 설정 합니다. 그 파일을 다음과 비슷하게 보일 겁니다:

# This needs to be uncommented before saslauthd will be run
# automatically
START=yes

PWDIR="/var/spool/postfix/var/run/saslauthd"
PARAMS="-m ${PWDIR}"
PIDFILE="${PWDIR}/saslauthd.pid"

# You must specify the authentication mechanisms you wish to use.
# This defaults to "pam" for PAM support, but may also include
# "shadow" or "sasldb", like this:
# MECHANISMS="pam shadow"

MECHANISMS="pam"
[참고]

만약 여러분이 좋아한다면, shadowpam 대신에 사용할 수 있습니다. 이것은 MD5 해쉬된 암호 전송을 사용하고 완전하게 안전 합니다. 인증을 하기 위하여 필요한 사용자 이름과 암호는 여러분이 사용하는 서버 시스템의 사용자의 그것들이 됩니다.

Next, update the dpkg "state" of /var/spool/portfix/var/run/saslauthd. The saslauthd init script uses this setting to create the missing directory with the appropriate permissions and ownership:

sudo dpkg-statoverride --force --update --add root sasl 755 /var/spool/postfix/var/run/saslauthd

테스팅

SMTP AUTH 설정을 마쳤습니다. 이제는 그것을 시작하고 설정을 테스트할 시간 입니다. SASL 데몬을 시작하기 위하여 다음의 명령을 실행할 수 있습니다:

          
            sudo /etc/init.d/saslauthd start
          
        

SMTP-AUTH과 TLS가 적절하게 동작하는 지를 보려면, 다음의 명령을 실행 합니다:

          
            telnet mail.example.com 25
          
        

여러분이 postfix 메일 서버로 접속을 만들고 난 후,

ehlo mail.example.com

을 입력하고 만약 다음의 줄들을 다른 것과 보게 된다면, 모든 것은 완전하게 동작하는 것 입니다. quit를 입력하여 종료 하십시오.

250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME