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 는 여러분의 메일 서버 호스트 이름으로 대체 합니다. |
이제 어느 메일박스 형식을 사용할 지를 결정해야 합니다. 기본적으로 Postfix 는 mbox 형식을 사용할 것입니다. 설정 파일을 직접 수정하는 대신, postconf 명령어를 통해 모든 postfix 파라미터들을 설정할 수 있습니다. 설정 파라미터들은 /etc/postfix/main.cf
파일에 저장될 것입니다. 이후에 특정 파라미터를 변경하고 싶다면, 이 명령을 실행하거나 설정 파일을 직접 수정할 수 있습니다.
Maildir 형식의 메일박스를 사용하도록 설정하려면:
sudo postconf -e 'home_mailbox = Maildir/'
![]() |
|
이제 새로운 메일이 도착하면 /home/사용자 이름/Maildir 에 저장될 것입니다. 따라서 메일 전송 에이전트도 같은 경로를 사용하도록 설정해야 할 것입니다. |
다음 단계는 SMTP 인증을 위해 SASL 을 사용하기 위해 postfix 를 설정하는 것입니다.
SASL (saslauthd) 을 이용해 SMTP AUTH 을 수행하도록 Postfix 를 설정하려면:
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
다음으로 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)에서 디지털 인증서를 받을 수 있습니다. 혹은 여러분 스스로 인증서를 생성할 수도 있습니다. 자세한 사항은 스스로 서명한 인증서 만들기 부분을 살펴보십시오. |
주고받는 메일 모두에 TLS 암호화를 사용하도록 Postfix 를 설정하려면:
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'
SMTP 서버를 위한 chroot 작업을 중지합니다. /etc/postfix/master.cf
파일에서 다음과 같은 줄을 찾습니다:
smtp inet n - - - - smtpd
이를 다음과 같이 수정합니다:
smtp inet n - n - - smtpd
![]() |
|
명령을 모두 실행하고 나면 postfix를 위한 SMTP AUTH의 설정이 모두 끝납니다. postfix에서 이어서 TLS에서 사용할 인증서를 직접 서명하여 설정합니다. |
이때 /etc/postfix/main.cf
와 this이 같아보여야 합니다.
Postfix의 초기 설정이 이제 끝났습니다. Postfix 데몬을 시작하려면
sudo /etc/init.d/postfix start
을 실행하십시오. 이제 postfix 데몬이 무사히 설치되었으며, 설정이 끝나고 이제 실행중입니다. Postfix는 RFC2554에서 정의한 SMTP AUTH를 지원하며, SASL를 따르고 있습니다. 하지만 SMTP를 사용기 위해서는 SASL 인증도 설정해야 합니다.
libsasl2-2, sasl2-bin, libsasl2-modules 들은 SASL 을 사용한 SMTP 인증을 수행하기 위해 필요합니다. 이 프로그램들이 아직 설치되지 않았다면, 다음과 같이 서치할 수 있습니다.
sudo apt-get install libsasl2-2 sasl2-bin
이것이 제대로 동작하기 위해서는 약간의 수정이 필요합니다. 왜냐하면 Postfix 는 /var/spool/postfix
에서 chroot 를 통해 실행되기 때문에, SASL 다른 루트 디렉토리에서 실행되도록 설정해야 하기 때문입니다 (/var/run/saslauthd
가 /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"
![]() |
|
만약 여러분이 좋아한다면, shadow를 pam 대신에 사용할 수 있습니다. 이것은 MD5 해쉬된 암호 전송을 사용하고 완전하게 안전 합니다. 인증을 하기 위하여 필요한 사용자 이름과 암호는 여러분이 사용하는 서버 시스템의 사용자의 그것들이 됩니다. |
다음으로, /var/spool/portfix/var/run/saslauthd
의 dpkg "상태" (state) 를 업데이트 합니다. saslauthd 의 init 스크립트는 이 설정을 이용해 존재하지 않는 디렉토리를 적절한 접근 권한과 소유자를 지정하여 생성합니다:
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