Настройка почты · 4 min read · Oct 26, 2025
Идеальная настройка - Debian Etch (Debian 4.0) - Страница 5
11 Postfix с SMTP-AUTH и TLS
Чтобы установить Postfix с SMTP-AUTH и TLS, выполните следующие шаги:
apt-get install postfix libsasl2 sasl2-bin libsasl2-modules libdb3-util procmailВам будет задано два вопроса. Ответьте следующим образом:
Общий тип конфигурации? <– Интернет-сайт
Имя почты? <– server1.example.com
Затем выполните
dpkg-reconfigure postfixСнова вам будут заданы несколько вопросов:
Общий тип конфигурации? <– Интернет-сайт
Куда должна идти почта для root? <– [пусто]
Имя почты? <– server1.example.com
Другие назначения для приема почты? (пусто для ничего) <– server1.example.com, localhost.example.com, localhost.localdomain, localhost
Принудительные синхронные обновления в очереди почты? <– Нет
Локальные сети? <– 127.0.0.0/8
Использовать procmail для локальной доставки? <– Да
Ограничение размера почтового ящика <– 0
Символ расширения локального адреса? <– +
Интернет-протоколы для использования? <– все
Далее выполните:
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
После этого создаем сертификаты для 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.crtopenssl rsa -in smtpd.key -out smtpd.key.unencryptedmv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
Далее настраиваем Postfix для TLS:
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’
postconf -e ‘myhostname = server1.example.com’
Файл /etc/postfix/main.cf теперь должен выглядеть так:
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 (Debian/GNU) 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 # 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:${queue_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${queue_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_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 |
Перезапустите Postfix:
/etc/init.d/postfix restartАутентификация будет выполняться с помощью saslauthd. Нам нужно изменить несколько вещей, чтобы это работало правильно. Поскольку Postfix работает в chroot в /var/spool/postfix, нам нужно сделать следующее:
mkdir -p /var/spool/postfix/var/run/saslauthdТеперь нам нужно отредактировать /etc/default/saslauthd, чтобы активировать saslauthd. Установите START в yes и измените строку OPTIONS=”-c” на OPTIONS=”-c -m /var/spool/postfix/var/run/saslauthd -r”:
vi /etc/default/saslauthd| # # Settings for saslauthd daemon # # Should saslauthd run automatically on startup? (default: no) START=yes # 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) # See the saslauthd man page for information about these options. # # Example for postfix users: "-c -m /var/spool/postfix/var/run/saslauthd" # Note: See /usr/share/doc/sasl2-bin/README.Debian OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r" |
Теперь запустите saslauthd:
/etc/init.d/saslauthd startЧтобы проверить, работают ли SMTP-AUTH и TLS, выполните следующую команду:
telnet localhost 25После того как вы установите соединение с вашим почтовым сервером Postfix, введите
ehlo localhostЕсли вы видите строки
250-STARTTLSи
250-AUTH PLAIN LOGINвсе в порядке.
Вывод на моей системе выглядит так:
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 (Debian/GNU)
ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
Введите
quitчтобы вернуться в оболочку системы.
12 Courier-IMAP/Courier-POP3
Запустите это, чтобы установить Courier-IMAP/Courier-IMAP-SSL (для IMAPs на порту 993) и Courier-POP3/Courier-POP3-SSL (для POP3s на порту 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Вам будет задано два вопроса:
Создать каталоги для веб-администрирования? <– Нет
Требуется SSL-сертификат <– Ок
Если вы не хотите использовать ISPConfig, настройте Postfix для доставки электронной почты в Maildir пользователя*:
postconf -e ‘home_mailbox = Maildir/‘
postconf -e ‘mailbox_command =’
/etc/init.d/postfix restart
*Пожалуйста, обратите внимание: Вам не нужно делать это, если вы собираетесь использовать ISPConfig на вашей системе, так как ISPConfig выполняет необходимую настройку с использованием рецептов procmail. Но, пожалуйста, убедитесь, что Maildir включен в разделе Управление -> Сервер -> Настройки -> EMail в веб-интерфейсе ISPConfig.
Get new posts in your inbox
No spam. Unsubscribe anytime.