Configuração de um servidor OpenSUSE 10.3 com Apache/SSL, Postfix, SMTP-AUTH e TLS, BIND, Proftpd , MySQL, Dovecot POP3/IMAP, Quota, Firewall, ISPConfig – Parte 5

Se você quer ver todas as partes do tutorial estão aqui:

Parte 1 – Parte2 – Parte3 – Parte4 – Parte 5 – Parte 6

Parte 5 (penultima parte do tutorial gigante)

9 Postfix com SMTP-AUTH e TLS

Agora, vamos instalar o Postfix e o Cyrus-SASL:

yast2 -i postfix cyrus-sasl cyrus-sasl-crammd5 cyrus-sasl-digestmd5 cyrus-sasl-gssapi cyrus-sasl-otp cyrus-sasl-plain cyrus-sasl-saslauthd procmail

Então, adicionaremos os links de inicialização do sistema para o Postfix e para o saslauthd e os inicializaremos:

chkconfig –add postfix
/etc/init.d/postfix start

chkconfig –add saslauthd
/etc/init.d/saslauthd start

Depois disto, criaremos os certificados para o 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

Agora, configuraremos os Postfix para o SMTP-AUTH e para o TLS

postconf -e ‘mydomain = example.com’
postconf -e ‘myhostname = server1.$mydomain’
postconf -e ‘mynetworks = 127.0.0.0/8′
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,check_relay_domains’
postconf -e ‘inet_interfaces = all’
postconf -e ‘alias_maps = hash:/etc/aliases’
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’

Para habilitar as conexões ao TLS no Postfix, edite o arquivo /etc/postfix/master.cf e descomente a linha do tlsmgr de forma que fique parecida com esta:

vi /etc/postfix/master.cf

[...]
tlsmgr    unix  -   -   n   1000?   1   tlsmgr
[...]

Agora, reinicialize o Postfix:

/etc/init.d/postfix restart

Para ver se SMTP-AUTH e o TLS estão funcionando propriamente, execute agora o seginte comando:

telnet localhost 25

Depois que você tiver estabelecido a conexão com o sevidor de e-mail Postfix, digite

ehlo localhost

Se você vir as linhas

250-STARTTLS

e

250-AUTH LOGIN PLAIN

então, tudo está bem.

No meu sistema, a saída se parece com esta:

server1:/etc/postfix/ssl # telnet localhost 25
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
220 server1.example.com ESMTP Postfix
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.
server1:/etc/postfix/ssl #

Digite

quit

para retornar o shell do sistema.

10 Courier-IMAP/Courier-POP3

Quero utilizar um daemon POP3/IMAP que possi suporte a Maildir. Por isot, eu utilizo Courier-IMAP e Courier-POP3.

yast2 -i courier-imap fam-server courier-authlib expect tcl

Então, adicionaremos os links de inicialização do sistema e inicializaremos os serviços POP3, IMAP, POP3 and IMAP:

chkconfig –add fam
chkconfig –add courier-authdaemon
chkconfig –add courier-pop
chkconfig –add courier-imap
/etc/init.d/courier-pop start
/etc/init.d/courier-imap start
chkconfig –add courier-pop-ssl
chkconfig –add courier-imap-ssl
/etc/init.d/courier-pop-ssl start
/etc/init.d/courier-imap-ssl start

Se você não quiser utilizar o ISPConfig, configure o Postfix par aentregar e-mails para o Maildir do usuário*:

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

*Observação: Você não tem que fazer isto se pretende instalar o ISPConfig em seu sistema, já que o ISPConfig realiza a configuração necessária utilizando receitas procmail. Mas, por favor, tenha certeza de habilitar o Maildir em Management -> Server -> Settings -> EMail na interface web do ISPConfig.

11 Apache/PHP5

Agora, instalaremos o Apache com o PHP5:

yast2 -i apache2 apache2-devel apache2-mod_perl apache2-mod_php5 apache2-prefork perl-HTML-Parser perl-HTML-Tagset perl-Tie-IxHash perl-URI perl-libwww-perl php5 php5-devel zlib zlib-devel

Então, instalaremos alguns módulos PHP5:

yast2 -i php5-bcmath php5-bz2 php5-calendar php5-ctype php5-curl php5-dbase php5-dom php5-ftp php5-gd php5-gettext php5-gmp php5-iconv php5-imap php5-ldap php5-mbstring php5-mcrypt php5-mhash php5-mysql php5-ncurses php5-odbc php5-openssl php5-pcntl php5-pgsql php5-posix php5-shmop php5-snmp php5-soap php5-sockets php5-sqlite php5-sysvsem php5-tokenizer php5-wddx php5-xmlrpc php5-xsl php5-zlib php5-exif php5-fastcgi php5-pear php5-sysvmsg php5-sysvshm ImageMagick curl

Agora, editaremos o arquivo /etc/apache2/httpd.conf:

vi /etc/apache2/httpd.conf

e alteremos DirectoryIndex para

[...]
DirectoryIndex index.html index.htm index.shtml index.cgi
index.php index.php5 index.php4 index.php3 index.pl
index.html.var index.aspx default.aspx
[...]

Edite o arquivo /etc/sysconfig/apache2 e edicione rewrite na linha APACHE_MODULES:

vi /etc/sysconfig/apache2

[...]
APACHE_MODULES="actions alias auth_basic authn_file authz_host
authz_groupfile authz_default authz_user authn_dbm autoindex cgi
 dir env expires include log_config mime negotiation setenvif ssl
suexec userdir php5 rewrite"
[...]

Também, adicione SSL à linha APACHE_SERVER_FLAGS:

[...]APACHE_SERVER_FLAGS="SSL"[...]

Agora, configure seu sistema para inicializar o Apache no boot:

chkconfig –add apache2

Então, execute

SuSEconfig
/etc/init.d/apache2 start

11.1 Desabilitar PHP e Perl globalmente

(Se você não planeja instalar o ISPConfig neste servidor, por favor, pule esta seção!)

No ISPConfig, você configurará o PHP e o Perl por website, ex: você poderá especificar que website pode executar scripts PHP e Perl e quais não podem. Isto somente poderá funcionar se o PHP e o Perl estiverem desabilitados globalmente, porque, de outra forma, todos os websites poderiam executar scripts PHP/Perl, independentemente do que você especificar no ISPConfig.

Para desabilitar o PHP e o Perl globalmente, editaremos o arquivo /etc/mime.types e comentaremos as linhas application/x-perl e application/x-php:

vi /etc/mime.types

[...]#application/x-perl pl pm al perl

#application/x-php php php3 php4

[...]

Então, edite o arquivo /etc/apache2/conf.d/php5.conf e comente todas as linhas AddHandler:

vi /etc/apache2/conf.d/php5.conf

<IfModule mod_php5.c>

        #AddHandler application/x-httpd-php .php4
        #AddHandler application/x-httpd-php .php5
        #AddHandler application/x-httpd-php .php
        #AddHandler application/x-httpd-php-source .php4s
        #AddHandler application/x-httpd-php-source .php5s
        #AddHandler application/x-httpd-php-source .phps
        DirectoryIndex index.php4
        DirectoryIndex index.php5
        DirectoryIndex index.php

</IfModule>

Logo após, reinicialize o Apache:

/etc/init.d/apache2 restart