PROJET AUTOBLOG


Planet-Libre

source: Planet-Libre

⇐ retour index

Jeyg : Un serveur mail Debian avec Postfix et Dovecot

jeudi 20 août 2015 à 19:47

Les e-mails, c'est chouette, mais plus grand monde n'utilise son propre serveur mail. Et c'est bien triste. Alors mettons-en un en place. Tant qu'à faire, autant qu'il soit sécurisé, donc on va faire les choses proprement.

Nous allons utiliser Debian 8, avec Postfix comme serveur SMTP, et Dovecot pour l'IMAP. Dovecot va aussi gérer l'authentification, via SASL. Le tout saupoudré de chiffrement: IMAPS + SMTPS.

Je considère que vous avez un nom de domaine (example.com) avec un enregistrement DNS adéquat ainsi que des certificats SSL. Sinon, vous pouvez toujours générer une paire certificat/clé auto-signée:

# openssl req -x509 -nodes -days 3650 -newkey rsa:4096 -out /etc/ssl/certs/mail.crt -keyout /etc/ssl/private/mail.key

Bien, on installe tout, et on y va.

# aptitude install postfix dovecot-imapd

Postfix

Note: configurations non-exhaustives, j'essaie de capturer l'essentiel.

## /etc/postfix/main.cf

# Hostname and domain name
myhostname=mymachine.example.com
mydomain=example.com
myorigin=$mydomain

# SSL/TLS certificates
smtpd_tls_cert_file=/etc/ssl/certs/mail.crt
smtpd_tls_key_file=/etc/ssl/private/mail.key
smtpd_use_tls=yes
smtpd_tls_auth_only=yes

# ~/Maildir directories
home_mailbox = Maildir/

# SASL
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
## /etc/postfix/master.cf

smtps     inet  n       -       -       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
# service postfix restart

Dovecot

Dans le dossier /etc/dovecot/conf.d:

## 10-ssl.conf

# SSL/TLS support: yes, no, required.
ssl = required
ssl_cert = ssl_key =
## 10-master.conf

service imap-login {
  inet_listener imap {
    #port = 143
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}

service auth {
 # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix
  }
}
## 10-auth.conf

# Disable LOGIN command and all other plaintext authentications unless
# SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
# matches the local IP (ie. you're connecting from the same computer), the
# connection is considered secure and plaintext authentication is allowed.
# See also ssl=required setting.
disable_plaintext_auth = yes

auth_mechanisms = plain login
# service dovecot restart

Configuration du client

Server: example.com
Username: linux user login
Password: linux user password
IMAP: SSL/TLS port 993
SMTP: SSL/TLS port 465

Debug

## The mail logs.
# tail -f /var/log/mail.log

## Display the postfix configs.
# postconf -n

## Display the dovcot configs.
# doveconf -n

Aller plus loin

Nous avons à présent un serveur SMTP et IMAP fonctionnel. Il pourrait être utile d'ajouter un anti-spam, un anti-virus, ainsi que le support du Sender Policy Framework (SPF) et du DomainKeys Identified Mail (DKIM). De bien joyeux sujets, que j'aborderai sans doute un jour.

Gravatar de Jeyg
Original post of Jeyg.Votez pour ce billet sur Planet Libre.