The Perfect Server - Ubuntu Hardy Heron (Ubuntu 8.04 LTS Server) časť 5

<!-- @page { margin: 2cm } A:link { so-language: zxx } -->

15 Postfix s SMTP-AUTH a TLS

Na to aby sme nainštalovali Postfix s SMTP-AUTH a TLS musíme urobiť nasledujúce kroky:

apt-get install postfix libsasl2-2 sasl2-bin libsasl2-modules procmail

 

 

 

 

 

 

Budú vám položené dve otázky.Odpovedajte takto:

General type of mail configuration: <-- Internet Site
System mail name: <-- server1.example.com

Potom spusťte:

dpkg-reconfigure postfix

 

 

 

Znovu vám budú položené ďalšie otázky:

General type of mail configuration: <-- Internet Site
System mail name: <-- server1.example.com
Root and postmaster mail recipient: <-- [blank]
Other destinations to accept mail for (blank for none): <-- server1.example.com, localhost.example.com, localhost.localdomain, localhost
Force synchronous updates on mail queue? <-- No
Local networks: <-- 127.0.0.0/8
Use procmail for local delivery? <-- Yes
Mailbox size limit (bytes): <-- 0
Local address extension character: <-- +
Internet protocols to use: <-- all

 

 

 

 

 

 

 

 

Ďalej, urobte toto:

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_sasl_authenticated_header = 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

 

 

 

 

 

 

 

 

 

 

 

 

 

Potom vytvoríme certifikáty pre TLS:

mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
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 3650 -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

 

 

 

 

 

 

 

 

 

Ako ďalšie nakonfigurujeme Postfix pre TLS(uistite sa, že používate správné hostname pre myhostname):

postconf -e 'myhostname = server1.example.com'

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/postfix/ssl/smtpd.key'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'
postconf -e 'smtpd_tls_CAfile = /etc/postfix/ssl/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'

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Súbor /etc/postfix/main.cf by mal vyzerať takto:

cat /etc/postfix/main.cf

 

 

 

 

 

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_use_tls = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = server1.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = server1.example.com, localhost.example.com, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
smtpd_sasl_local_domain =
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

 

 

 

 

 

 

 

 

 

 

 

 

Autetifikácia sa vykoná pomocou saslauthd. Musíme zmeniť niekoľko vecí aby to pracovalo v poriadku. Pretože Postfix beží „chrooted“ v /var/spool/postfix musíme urobiť nasledovne kroky:

mkdir -p /var/spool/postfix/var/run/saslauthd

 

 

 

 

 

 

Teraz musíme editovať /etc/default/saslauthd aby sme aktivovali saslauthd. Nastavíme START na „yes“ a zmeníme riadok OPTIONS="-c -m /var/run/saslauthd" na OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"

vi /etc/default/saslauthd

 

 

#
# Settings for saslauthd daemon
# Please read /usr/share/doc/sasl2-bin/README.Debian for details.
#

# Should saslauthd run automatically on startup? (default: no)
START=yes

# Description of this saslauthd instance. Recommended.
# (suggestion: SASL Authentication Daemon)
DESC="SASL Authentication Daemon"

# Short name of this saslauthd instance. Strongly recommended.
# (suggestion: saslauthd)
NAME="saslauthd"

# Which authentication mechanisms should saslauthd use? (default: pam)
#
# Available options in this Debian package:
# getpwent -- use the getpwent() library function
# kerberos5 -- use Kerberos 5
# pam -- use PAM
# rimap -- use a remote IMAP server
# shadow -- use the local shadow password file
# sasldb -- use the local sasldb database file
# ldap -- use LDAP (configuration is in /etc/saslauthd.conf)
#
# Only one option may be used at a time. See the saslauthd man page
# for more information.
#
# Example: MECHANISMS="pam"
MECHANISMS="pam"

# Additional options for this mechanism. (default: none)
# See the saslauthd man page for information about mech-specific options.
MECH_OPTIONS=""

# How many saslauthd processes should we run? (default: 5)
# A value of 0 will fork a new process for each connection.
THREADS=5

# Other options (default: -c -m /var/run/saslauthd)
# Note: You MUST specify the -m option or saslauthd won't run!
#
# See /usr/share/doc/sasl2-bin/README.Debian for Debian-specific information.
# See the saslauthd man page for general information about these options.
#
# Example for postfix users: "-c -m /var/spool/postfix/var/run/saslauthd"
#OPTIONS="-c -m /var/run/saslauthd"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"

 

Teraz pridáme postfix uživateľa k „sasl“ skupine(budeme si istý že Postfix nám pridá povolenie k prístupu na „saslauthd“:

adduser postfix sasl

 

 

 

 

Teraz reštartujeme Postfix a spustíme „saslauthd“:

/etc/init.d/postfix restart
/etc/init.d/saslauthd start

 

 

 

 

 

Na to aby sme videli či SMTP-AUTH a TLS pracuje správne spustíme nasledujúci prikaz:

telnet localhost 25

 

 

 

 

Potom ako sme stanovili pripojenie k vášmu Postfix mail servru napíšeme:

 

ehlo localhost

 

 

 

 

Uvidíte riadky

250-STARTTLS

a

250-AUTH LOGIN PLAIN

všetko je v poriadku

Výstup na mojom počitáči vyzeral takto:

root@server1:/etc/postfix/ssl# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 server1.example.com ESMTP Postfix (Ubuntu)
ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
root@server1:/etc/postfix/ssl#

 

Napíšte

quit

 

 

 

 

aby sme sa vrátili k systemovemu shellu..

 

16 Courier-IMAP/Courier-POP3

Aby sme to spustili nainštalujeme Courier-IMAP/Courier-IMAP-SSL (pre IMAPs na porte 993) a Courier-POP3/Courier-POP3-SSL (pre POP3s na porte 995):

apt-get install courier-authdaemon courier-base courier-imap courier-imap-ssl courier-pop courier-pop-ssl courier-ssl gamin libgamin0 libglib2.0-0

 

 

 

 

 

 

Budú vám položené dve otázky:

Create directories for web-based administration? <-- No
SSL certificate required <-- Ok

Ak nechcete použivať ISPConfig, nastavte Postfix na donášanie emailov k uživateľovmu Maildir*:

postconf -e 'home_mailbox = Maildir/'
postconf -e 'mailbox_command ='
/etc/init.d/postfix restart

 

 

 

 

 

*Upozornenie: Nemusíte to robiť pokiaľ zamyšľate nad používaním ISPConfig vo vašom systéme pretože ISPConfig vykonáva všetky dôležité konfigurácie použitím „procmail“. Ale prosim uistite sa či máte aktivovaný Maildir v ISPConfig web rozhraní.(Management -> Server -> Settings -> EMail)