[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

¡Esta es una revisión vieja del documento!


Site under translation, please wait (pedro.herrero)

Creación de un servidor de correo Slackware

This article shows how to make an Slackware machine your personal Mail Server. This howto is for Slackware 64 13.37, but with few changes you can adapt it to the newest member of Slackware familly Slackware 14. Before we begin I must say that you need a normal installation of Slackware, without any special packages. The packages we will need to make the Mail Server we will manually download and install from Slackbuilds.org. I preffer the Cyrus SASL authentication method and Cyrus IMAP for remote login, insted of other alternatives like qpopper or dovecot. Let's get started then , we will need to install Cyrus-SASL, Postfix, Cyurs-IMAP and then configure them all to use Certificates for encrypting the mail packages that traverse the Internet.

Este artículo muestra cómo hacer de una máquina Slackware su servidor de correo personal. Este cómo es para Slackware 64 13.37, pero con pocos cambios puedes adaptarlo al más nuevo miembro de la familia Slackware 14.

Antes de empezar debo decir que se necesita una instalación normal de Slackware, sin ningún paquete especial. Los paquetes que necesitaremos para crear el servidor de correo los descargaremos e instalaremos manualmente desde Slackbuilds.org. Prefiero el método de autenticación Cyrus SASL y Cyrus IMAP para el inicio de sesión remoto, en lugar de otras alternativas como qpopper o dovecot.

Comencemos entonces, necesitaremos instalar Cyrus-SASL, Postfix, Cyurs-IMAP y luego configurarlos todos para que usen Certificados para encriptar los paquetes de correo que atraviesan Internet.

Instalación de Cyrus-SASL

# cd /tmp
# mkdir cyrus-sasl
# cd cyrus-sasl
# wget ftp://ftp.slackware.com/pub/slackware/slackware64-13.37/source/n/cyrus-sasl/cyrus-sasl-2.1.23.tar.xz
# wget ftp://ftp.slackware.com/pub/slackware/slackware64-13.37/source/n/cyrus-sasl/cyrus-sasl.SlackBuild
# wget ftp://ftp.slackware.com/pub/slackware/slackware64-13.37/source/n/cyrus-sasl/doinst.sh.gz
# wget ftp://ftp.slackware.com/pub/slackware/slackware64-13.37/source/n/cyrus-sasl/rc.saslauthd.gz
# wget ftp://ftp.slackware.com/pub/slackware/slackware64-13.37/source/n/cyrus-sasl/slack-desc
# joe cyrus-sasl.SlackBuild

y añada las siguientes líneas después de “–disable static”

--enable-plain \
--disable-digest \
# sh cyrus-sasl.SlackBuild
# installpkg /tmp/cyrus-sasl-2.1.23-x86_64-1.txz

Instalación de Postfix

# cd /tmp
# mkdir postfix
# cd postfix
# wget http://postfix.cs.utah.edu/source/official/postfix-2.8.3.tar.gz
# wget http://slackbuilds.org/slackbuilds/13.37/network/postfix/README
# wget http://slackbuilds.org/slackbuilds/13.37/network/postfix/doinst.sh
# wget http://slackbuilds.org/slackbuilds/13.37/network/postfix/postfix.SlackBuild
# wget http://slackbuilds.org/slackbuilds/13.37/network/postfix/postfix.info
# wget http://slackbuilds.org/slackbuilds/13.37/network/postfix/rc.postfix
# wget http://slackbuilds.org/slackbuilds/13.37/network/postfix/slack-desc
# joe postfix.Slackbuild

Edite la siguiente línea y sustituya “dovecot” por “cyrus” de la siguiente manera

SASL=${SASL:-cyrus}

Para comenzar la instalación de Postfix necesitará crear un usuario y un grupo de postfix (también tenga en cuenta que necesitamos añadir el usuario postfix y el usuario cyrus al mismo grupo, es decir, al mismo grupo de correo).

# groupadd -g 200 postfix
# useradd -u 200 -d /dev/null -s /bin/false -g postfix postfix -G mail
# groupadd -g 201 postdrop
# sh postfix.SlackBuild  
# installpkg /tmp/postfix-2.8.3-x86_64-1_SBo.tgz 

Before we continue with installation of IMAP server we need to assure that Postfix is working and we can authenticate with sasl. Let's make some basic Postfix configuration and some basic SASL configuration. I will be explaining plain auth because later on we will use it togheter with SASL to authenticate.

Antes de continuar con la instalación del servidor IMAP necesitamos asegurarnos de que Postfix funciona y que podemos identificarnos con sasl. Vamos a hacer una configuración básica de Postfix y una configuración básica de SASL. Estaré explicando la identificación simple porque más tarde la usaremos junto con SASL para identificarnos.

First of all we need to make our aliases and tell Postfix to use aliases maps from /etc/postfix/aliases, so :

En primer lugar tenemos que hacer nuestros alias y decirle a Postfix que utilice los mapas de alias de /etc/postfix/aliases, así que… :

# joe /etc/postfix/main.cf

Edita estas líneas y haz que tengan el siguiente aspecto:

alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases  

Ahora vamos a añadir un usuario a la máquina Slackware, un usuario que también pueda leer y enviar correo.

# adduser

Login name for new user []: slackware_user
User ID ('UID') [ defaults to next available ]: pulse ENTER
Initial group [ users ]: 200
Home directory [ /home/xxxxxx ]: pulse ENTER
Shell [ /bin/bash ]: /bin/false
Do you wish to change the sheel? (Y/n): n
Expiry date (YYYY-MM-DD) []: pulse ENTER
Presione ENTER e introduzca el nombre completo y otras cosas relacionadas con la cuenta. También especifique una contraseña para el usuario recién creado.

Ahora edite /etc/postfix/aliases y modifíquelo según sus necesidades:

root  :         slackware_user
office:	  slackware_user

Ahora actualice su base de datos de alias con el comando..:

# postalias hash:/etc/postfix/aliases   

Ahora es el momento de hacer nuestras configuraciones importantes para Postfix para que funcione.

# joe /etc/postfix/main.cf
myhostname = mx.tudominio.tld
mydomain = tudominio.tld 
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8

Ahora configuremos Postfix para autenticar usuarios usando SASL

# mkdir /etc/sasl2
# cd /etc/sasl2
# touch smtpd.conf
# joe smtpd.conf 
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN

Ahora vamos a configurar Postfix para que los usuarios se identifiquen usando SASL. Edite /etc/postfix/main.cf y añada el siguiente código al final del archivo:

smtpd_sasl_auth_enable = yes   
broken_sasl_auth_clients = yes  
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

Iniciemos los demonios y probemos nuestras configuraciones hasta ahora:

# saslauthd -a shadow
# postfix start

Luego, desde otra máquina haga telnet a su servidor de correo en el puerto 25 y ejecute los siguientes comandos :

# telnet mx.mailserver.com 25
ehlo user.mailserver.tld   
250-mx.mailserver.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
AUTH PLAIN Y4R0QYxpcuHsFBRbbGjnPHIwYjB0MWrpMTk7La==
235 2.7.0 Authentication successful
MAIL FROM: <user@mailserver.com>
250 2.1.0 Ok
RCPT TO: <user@yahoo.com>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
HI. This mail is a test .
.
250 2.0.0 Ok: queued as 4C0EE221E93
QUIT
Para encontrar la cadena después de AUTH PLAIN introduzca el comando printf 'user\0user\0password' | mmencode en su servidor de correo, donde usuario es su nombre de usuario y contraseña es su contraseña.
Recuerde poner el “.” al final para que el correo pueda ser enviado a la cola del demonio.

Instalación de Mail Delivery y Cyrus IMAP

# cd /tmp
# mkdir cyrus-imap
# cd cyrus-imap
# wget http://cyrusimap.org/releases/cyrus-imapd-2.4.12.tar.gz
# wget http://slackbuilds.org/slackbuilds/13.37/network/cyrus-imapd/README
# wget http://slackbuilds.org/slackbuilds/13.37/network/cyrus-imapd/README.SLACKWARE
# wget http://slackbuilds.org/slackbuilds/13.37/network/cyrus-imapd/cyrus-imapd.SlackBuild
# wget http://slackbuilds.org/slackbuilds/13.37/network/cyrus-imapd/cyrus-imapd.info
# wget http://slackbuilds.org/slackbuilds/13.37/network/cyrus-imapd/doinst.sh
# wget http://slackbuilds.org/slackbuilds/13.37/network/cyrus-imapd/imapd.conf
# wget http://slackbuilds.org/slackbuilds/13.37/network/cyrus-imapd/patches
# wget http://slackbuilds.org/slackbuilds/13.37/network/cyrus-imapd/rc.cyrus-imapd
# wget http://slackbuilds.org/slackbuilds/13.37/network/cyrus-imapd/slack-desc
# mkdir patches
# cd patches/
# wget http://mirrors.vbi.vt.edu/mirrors/linux/slackbuilds/13.37/network/cyrus-imapd/patches/cyrus-imapd-2.4.4-autocreate-0.10-0-sv1.patch
# wget http://mirrors.vbi.vt.edu/mirrors/linux/slackbuilds/13.37/network/cyrus-imapd/patches/cyrus-imapd-2.4.4-autosieve-0.6.0-sv1.patch
# cd /tmp/cyrus-imap
# groupadd -g 238 cyrus
# useradd -d /var/imap -s /bin/sh -u 238 -g 238 cyrus -G mail 
# sh cyrus-imapd.SlackBuild
# installpkg /tmp/cyrus-imapd-2.4.12-x86_64-1_SBo.tgz
# mkdir -m 750 -p /var/imap /var/spool/imap /var/sieve
# chown cyrus:mail /var/imap /var/spool/imap /var/sieve
# su - cyrus
# /usr/doc/cyrus-imapd-2.4.12/tools/mkimap
# su - root

Edite /etc/imapd.conf y añada las siguientes líneas:

sasl_mech_list: PLAIN LOGIN
allowplaintext: yes  

Edite el archivo /etc/postfix/main.cf y añada lo siguiente en mailbox_transport:

mailbox_transport = lmtp:unix:/var/imap/socket/lmtp

El último paso es añadir usuarios a su servidor imap. Para ello es necesario que ejecute el siguiente comando:

# passwd cyrus

y añada una contraseña para el usuario cyrus

# cyradm --user cyrus --server localhost --auth plain    
localhost>cm user.slackware_user 
localhost>lm
localhost> quit
slackware_user es el usuario que haya creado en su máquina slackware

En este punto tenemos un servidor de correo funcional pero con usuarios identificándose en texto plano. Así que el siguiente paso es inevitable.

SSL / TLS Postfix and Cyrus

Let's start by creating our certificates and configuring POSTFIX to use STARTTLS.

# cd /etc/ssl
# misc/CA.pl -newca ( complete all entries)
# openssl req -new -nodes -keyout mailkey.pem -out mailreq.pem -days 36500
# openssl ca -out mail_signed_cert.pem -infiles mailreq.pem
# cp /etc/ssl/mailkey.pem /etc/postfix
# cp /etc/ssl/mail_signed_cert.pem /etc/postfix
# chown root /etc/postfix/mailkey.pem
# chmod 400 /etc/postfix/mailkey.pem
# cp /etc/ssl/demoCA/cacert.pem /etc/postfix

Now add the followings to /etc/postfix/main.cf :

smtpd_use_tls = yes
smtpd_tls_key_file = /etc/postfix/mailkey.pem
smtpd_tls_cert_file = /etc/postfix/mail_signed_cert.pem
smtpd_tls_CAfile = /etc/postfix/cacert.pem
In /etc/postfix/master.cf delete the “#” sign from smtps and the next two columns from it
                 smtps     inet  n       -       n       -       -       smtpd
                   -o smtpd_tls_wrappermode=yes
                   -o smtpd_sasl_auth_enable=yes

Now let's configure IMAP to use STARTTLS

# openssl req -new -nodes -out req.pem -keyout key.pem  
# openssl rsa -in key.pem -out new.key.pem
# openssl x509 -in req.pem -out ca-cert -req -signkey new.key.pem -days 36500
# cp new.key.pem /var/imap/server.pem
# rm new.key.pem
# cat ca-cert >> /var/imap/server.pem
# chown cyrus:mail /var/imap/server.pem
# chmod 600 /var/imap/server.pem 
# echo tls_ca_file: /var/imap/server.pem >> /etc/imapd.conf
# echo tls_cert_file: /var/imap/server.pem >> /etc/imapd.conf
# echo tls_key_file: /var/imap/server.pem >> /etc/imapd.conf 

Adding daemons to rc.local

Now the last step is to add all daemons to rc.local so they can start when machine boots. So open /etc/rc.d/rc.local and add these lines :

# Starting saslauthd daemon
if [ ! -r /var/state/saslauthd/saslauthd.pid ]; then
    echo "Starting SASL authentication daemon:  /usr/sbin/saslauthd -a shadow"
    /usr/sbin/saslauthd -a shadow
fi
# Starting IMAP daemon
if [ -x /usr/libexec/cyrus/master ]; then
    echo "Starting Cyrus IMAP daemon:  /usr/libexec/cyrus/master"
    /etc/rc.d/rc.cyrus-imapd start
fi
# Starting POSTFIX daemon
/etc/rc.d/rc.postfix start
   

Sources

Postfix The Definitive Guide, Kyle D. Dent, O'Reilly
Managing IMAP, Dianna Mullet & Kevin Mullet, O'Reilly
Official Postfix Documentation, [[http://www.postfix.org/documentation.html]]
 es:howtos:network_services:postfix_with_cyrus ()
Esta traducción es más antigua que la página original y podría estar obsoleta. Ver lo que ha cambiado.