사이트 내 전체검색
우분투 Mail Server Setting
로빈아빠
https://cmd.kr/server/967 URL이 복사되었습니다.

본문

우분투 Mail Server Setting

: 어떤 이는 간단하다고, 어떤 이는 복잡하다고.... 아직도 시원한 답은 모르겠다.

 

출처, 참고

http://www.postfix.org

http://sukwoo.blogspot.com/2008/08/ubuntu-mail-server.html

http://magicpd.tistory.com/6

http://dorm.tistory.com/4 : [Ubuntu]Postfix mail server with Courier-POP

http://www.ystory.kr/239  

http://www.linuxmail.info/smtp-authentication-postfix-centos-5/

 

1. 개요

: 네트워크 또는 인터넷 상에서 한 사람에서 부터 다른 사람으로 이메일을 가지는 과정은 많은 시스템이 함께 동작하는 것과 관련 됩니다. 각각의 시스템은 과정이 동작하기 위하여 반드시 올바르게 설정되어야 합니다. 보내는 사람은 Mail User Agent (MUA) 또는 이메일 클라이언트를 사용하고, 메세지를 보내기 위하여 하나 또는 여러 개의 Mail Transfer Agents (MTA) 를 통과하며, 마지막으로, 받는 사람의 메일박스에 배달을 하기 위하여 Mail Delivery Agent (MDA) 를 거치게 됩니다. 그리고, 메일은 보통 POP3 또는 IMAP 서버를 통하여 받는 사람의 이메일 클라이언트에 의해 읽혀지게 됩니다.

 

2. Postfix

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

: 메일을 보내주는 서버(smtp)이고 우분투설치시 기본적으로 깔리는 패키지입니다. 그렇지만 디폴트설정이 로컬머신에서만 서비스 해 주게 되어있습니다. 머신외부로부터의 요청에 대해서도 서비스 해 주기 위해서는 postfix 설정을 바꾸어줍니다(Internet Site)

 

/etc/postfix   : Postfix 관련폴더

/etc/postfix/main.cf   : Postfix 관련 설정파일

 

1) 설치

대부분 postfix는 설치되어 있다.

만약 설치되어 있지 않다면 postfix를 설치해야 한다.

 

< 설치 확인 방법 >

$ ps -ef|grep postfix

 

< 설치 방법 >

sudo apt-get install postfix

 apt-get install postfix sasl2-bin


2) 설정

$ sudo dpkg-reconfigure postfix

 

* 인터넷 사이트 선택

* 시스템 메일 이름 : 메일서버의 풀도메인명을 기입한다, DNS서버의 메일 도메인명을 기입하면 된다.

ex) mail.ecreditline.co.kr

 

나머지는 전부 기본 설정을 그대로 유지

 

3. SMTP 인증

 : 다음 단게는 SMTP AUTH를 위하여 SASL을 사용하도록 postfix를 설정하는 것. 2과 같이 postfix를 설정하더라도 외부에서 서버의 유저에게만 메일을 보낼수 있고, 서버를 거쳐 다른 곳으로 보낼수 없습니다(no relay). 또한 외부에서 postfix서비스를 사용하는데 인증절차를 거치지 않습니다. 따라서 relay를 할 경우 sasl로 인증절차를 밟도록 해줍니다. 따로 smtp 서버를 가지고 있지않은 XP Home edition이하에서의 outlook 같은 클라이언트들은 이러한 기능을 이용해 서버를 거쳐 메일을 다른곳으로 보내야 합니다

 

1) SASL을 사용하여 SMTP AUTH를 (saslauthd) 하도록 Postfix를 설정

: /etc/postfix/main.cf 수정

 

* gedit, vim 사용 : 설정 파일을 직접 편집

 

$ sudo gedit /etc/postfix/main.cf

- 다른 라인 수정하지 마시고, 제일 밑에다가 붙여넣는다. :  확인 필요함, 저 같은 경우 터미널로 이미 몇개의 명령어를 넣어놔서

- ()의 것은 설명입니다. 나중에 더 아는대로 추가할테니 뭍여 넣지 마세요.

 

home_mailbox = Maildir/   : 메일폴더 설정
mailbox_command =
smtpd_sasl_local_domain =
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_option = noanonymous
broken_sasl_auth_clients = yes   : MS Outlook Express 4.0, Exchange 5.0 같은 오래된 클라이언트를 지원하기 위함 
smtpd_recipient_restrictions =
permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
inet_interfaces = all

 

$ sudo gedit /etc/postfix/sasl/smtpd.conf

- 빈 문서 생성됨.

pwcheck_method:saslauthd
mech_list:plain login
두 줄 추가합니다.

 

* postconf 명령어로 터미널 상에서 수정 

postconf -e 'smtpd_sasl_local_domain ='
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'smtpd_sasl_security_options = noanonymous'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'inet_interfaces = all'
echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf
echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.conf

 

2) TLS를 위하여 디지털 인증서를 생성, 설정

 

 openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
278 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
....................................++++++
.......................++++++
e is 65537 (0x10001)
Enter pass phrase for smtpd.key:
Verifying - Enter pass phrase for smtpd.key:
$ chmod 600 smtpd.key
$ openssl req -new -key smtpd.key -out smtpd.csr
Enter pass phrase for smtpd.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) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
$ openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
Signature ok
subject=/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd
Getting Private key
Enter pass phrase for smtpd.key:
$ openssl rsa -in smtpd.key -out smtpd.key.unencrypted
Enter pass phrase for smtpd.key:
writing RSA key
$ mv -f smtpd.key.unencrypted smtpd.key
$ openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
Generating a 1024 bit RSA private key
.........++++++
..........++++++
writing new private key to 'cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
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) []:
Email Address []:
$ mv smtpd.key /etc/ssl/private/
$ mv smtpd.crt /etc/ssl/certs/
$ mv cakey.pem /etc/ssl/private/
$ mv cacert.pem /etc/ssl/certs/
$ ls -l
합계 8
-rw-r--r-- 1 root root  48 2009-09-28 15:40 smtpd.conf
-rw-r--r-- 1 root root 603 2009-09-28 17:32 smtpd.csr   : 이게 왜 남아 있을까....????
$

3) 들어오는 이메일과 나가는 이메일 모두에 TLS 암호화를 적용하도록 Postfix를 설정

 

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

* 명령을 모두 실행하고 나면 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 인증도 설정해야 합니다.

 

4) SASL 설정하기

SASL를 통한 SMTP AUTH 기능을 사용하기 위해서는 application>libsasl2

 

SASL를 제대로 사용하기 위해서는 수정해야 할 것이 몇 가지 있습니다. Postfix는 /var/spool/postfix 내에 chroot된 상태로 동작하기 때문에, SASL 역시 그 chroot된 환경 내에서 동작할 수 있도록 설정해야합니다(/var/run/saslauthd 대신에 /var/spool/postfix/var/run/saslauthd가 됩니다). 다음 명령을 입력하십시오:

 

mkdir -p /var/spool/postfix/var/run/saslauthd
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 script는 적당한 접근 권한과 소유권을 가지고 없는 디렉토리를 만들기 위하여 이 설정을 사용 합니다:

 

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

5) 테스팅

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

4. Exim4
Exim4는 인터넷에 연결된 유닉스 시스템 상에서 사용하도록 캠브리지 대학에서 개발한 또다른 Message Transfer Agent (MTA) 입니다. Exim은 sendmail 자리에 설치될 수 있고, 설정은 sendmail의 설정과는 아주 다릅니다.

 

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

sudo apt-get install exim4 exim4-base exim4-config

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

sudo dpkg-reconfigure exim4-config

사용자 인터페이스가 보여질 겁니다. 사용자 인터페이스는 여러분이 많은 파라미터를 설정할 수 있도록 합니다. 예를 들어, exim4 설정 파일은 여러 개의 파일들로 나누어 집니다. 만약 여러분이 그것들을 한 파일로 갖기를 원한다면 이 사용자 인터페이스에서 적절하게 설정할 수 있습니다.

여러분이 사용자 인터페이스에서 설정할 수 있는 모든 파라미터들은 /etc/exim4/update-exim4.conf.conf 파일에 저장 됩니다. 만약 재 설정하기를 원한다면, 설정 마법사를 재 실행하던지 또는 여러분이 선호하는 편집기를 사용하여 수작업으로 이 파일을 편집할 수 있습니다. 설정한 후, 주 설정 파일을 만들기 위하여 다음 명령을 실행할 수 있습니다:

sudo update-exim4.conf
주 설정 파일이 만들어지고 /var/lib/exim4/config.autogenerated로 저장 됩니다.

댓글목록

등록된 댓글이 없습니다.

1,139 (1/23P)

Search

Copyright © Cmd 명령어 18.118.200.197