|
|
Menu
Top 5 Articles
Stats
Thanks
Portland event planning courtesty of Event Ethos - www.eventethos.com
|
This article has been read 224930 times How To Install Postfix, Amavis, ClamAV, and Spamassassin
How To Install Postfix, Amavis, ClamAV, and Spamassassin on Debian
Linux Note: This article covers some basic Spam filtering. It is not the place for detailed UBE handling. I will soon be outlining a detailed How-To just for spam. I am also now focusing on Debian Sarge, so some of the latest additions to this How-To will not be tested for Woody. INTRODUCTION For the sake of clarity, I’ll be using "tobias.local"
for my domain, and 123.123.123.123 for my IP address. These values should
obviously be changed to your settings. Although this describes the install
process on Debian Linux, it should be the same on any flavor of Linux minus
the Debian-centric commands like “apt-get”.
This may be a rather terse guide, like a step by step to email, so if you’re
wanting more theory or explanation, read your man pages or see a more verbose
guide like one of these: INSTALLATION I’m running on Sarge (Testing), so if you’re running Stable you’ll
need to change some of your apt settings. You’ll have to grab a few
packages out of testing to for this install. If you’re running testing
you can skip this section. deb-src http://debian.oregonstate.edu/debian testing main non-free contrib and to /etc/apt/apt.conf: APT::Default-Release "stable"; What this does is say "pin all packages at stable" Now run: Or if you’re already running on Testing run: Say yes if it asks you to remove exim or whatever MTA you may have installed. CONFIGURATION Before we get too far along, we need to make sure Postfix is running properly,
then we’ll add more functionality later. All of Postfix’s configuration
files are located in /etc/postfix. If you open /etc/postfix/main.cf
(Appendix A) in your favorite text editor, you should see your domain information
in here from the Postfix install scripts you answered during the setup. We
also need to setup our Maildir mail boxes with the “maildirmake”
command. We’ll do this for existing users and also in /etc/skel
so new users automatically get the same setup. To setup our Maildir,
change directories to your home and run: Now repeat for /etc/skel. If your existing users are in
the mbox format, you can convert them to Maildir with the
mb2md command. To have Postfix deliver to Maildir, add the following line
to your main.cf: Test out your email and make sure everything works thus far. If all is working
properly, bring Maildrop online by finding (or adding) the
line to your main.cf file: Now send an email and you should see the details in the /var/log/maildrop
file. Since I want to use IMAPS and have installed courier-imap-ssl, I need to
set up a proper certificate. IMAP over SSL requires a valid, signed, X.509
certificate and one was generated during the install, but it’s bogus.
The command “mkimapdcert” generates
a self-signed X.509 certificate. To prevent an unfortunate accident, mkimapdcert
will not work if imapd.pem already exists, so we’ll
make a backup of it and make a new one. In /etc/courier copy
imapd.cnf to imapd.cnf.bak, and move imapd.pem
to imapd.pem.bak. Edit imapd.cnf to suit
you needs. Then to generate the new IMAPS certificate run: To run Amavis, you’ll have to setup your amavis.conf
file. I suggest reading the Postfix install doc for Amavis, /usr/share/doc/amavisd-new/README.postfix.gz
Open /etc/amavis/amavisd.conf, locate and change the
“$mydomain” section to your domain. Locate and comment out this line: To have Spamassassin add it’s header tags to mail, find the @local_domains_acl
= lines and change them to the following (don’t forget the
period in the parenthisis!): Tell Amavis how to handle spam and viruses. Although the RFC says you should let the sender know you're killing thier mail, it is a waste of bandwidth, as most virus/spam mail is spoofed, so locate and edit these lines: I have all mail related messages go to an account called “postmaster”.
I want all messages coming to the postmaster account regardless of spam or
virus content, so find and change the following lines: I don’t want to quarantine virused email, and spam will be delivered
to the users Junkmail folder, so I locate and changed the
following: Other related changes: Be sure to create the /var/log/amavis.log file and chown it to amavis. If you want Amavis to knock out emails with certain extensions tailor the
$banned_filename_re to meet your needs. To have Amavis pass email to Clam antivirus, comment out
all of the antivirus stanzas except for the two clamav stanzas. Also the ClamAV user needs access to the messages to be able to check them so add it to the Amavis group: Start amavis and check for typos. To see any error messages and debugging
info, I suggest running Amavis for the first time interactively and keep it
attached to the terminal by issuing the following comands:
--> $ telnet 127.0.0.1 10024 220 [127.0.0.1] ESMTP amavisd-new service ready --> quit 221 Bye Now add the following to the end of your /etc/postfix/master.cf file: smtp-amavis unix - - n - 2 smtp 127.0.0.1:10025 inet n - n - - smtpd Now add this to your /etc/postfix/main.cf: What all of this does is add a SMTP proxy. Mail comes into Postfix and is handed off to Amavis on port 10024. Amvais will then process the mail and hand it back to Postfix on port 10025. Now open /etc/courier/maildroprc and add: This should grab mail tagged by Spamassassin and put it in the user’s Junkmail folder. Reload Postfix. At this point, you should have a working installation that filters mail for viruses and spam. The only step left is to setup SMTP authentication so users can relay mail through the server without fear of spammers using it as an open relay. SMTP AUTH To enable users to relay messages through the server, they must authenticate with the server. Although there a several ways to do this, I like using PLAIN or LOGIN for compatibility reasons. Since we’ll be using the PLAIN or LOGIN mechanisms for SMTP AUTH, usernames and passwords are sent over the internet in plaintext. To keep anyone sniffing our traffic from seeing our credentials, we need to encrypt our traffic with Transport Layer Security, or TLS. We’ll setup all of this up in two steps. The first is configuring Postfix for SMTP authentication. The second step is setting up TLS for encrypting the users credentials. First we’ll have to install the Postfix ssl patch. To have Postfix authenticate users, we’ll pass the authentication to
SASL and let it do the actual query against the shadow file
via PAM. Create the /etc/postfix/sasl/smtpd.conf
file and enter the following: Now install the sasl apps: To have the the sasl authentication daemon listening where Postfix will be
looking for it, we’ll need to edit the init script for saslauthd.
Open the /etc/init.d/saslauthd file in your favorite editor
and enter the following line in the header (under PWDIR): Now we’ll have to make the directory we just added in the previous
step, chown it so Postfix can use it, and add the Postfix user to the sasl
group. To enable saslauthd to start, edit the /etc/default/saslauthd
file and add this: Start saslauthd and check that is running. Issue the following command: You should see: NOTE! Many people have had problems with sasl not working correctly.
This is almost always due to sasl not shuting down or acceptting the new settings. If you have problems with sasl, kill -9 all of its PID's or simply reboot.
To check that sasl is indeed working, use the testsaslauthd
command with your username and password: If everything is setup correctly, you should see: To have Postfix use sasl, you need to add this (preserving the spaces and commas!) to your main.cf: Restart Postfix, I think you have to actually restart postfix for this? Reload
didn't seem to work for me. To test, you’ll need to telnet to Postfix
and issue some commands, but since some of these are in base 64, you’ll
need to generate the command and copy the resultes. Enter this exactly like
it is below, but with your username and password! Don’t leave out the
0’s!! It should return a string like this: Now telnet to Postfix and enter the following case sensitive commands : Now add your base64 encoded string after AUTH PLAIN: You SHOULD see 235 Authentication successful. Your test should look something like this: If this isn’t working go back and double check your settings. Next we’ll be installing certificates and tls support to encrypt user information. SETTING UP TLS As stated previously, we’ll be using the PLAIN or
LOGIN mechanisms for SMTP AUTH, so usernames and passwords
are sent over the internet in plaintext. To keep anyone sniffing our traffic
from seeing our credentials, we need to encrypt our traffic with TLS. So if
you haven’t already, apt-get install postfix-tls. Now all that is left is to tell Postfix to use TLS. Add the following stanza to your /etc/postfix/main.cf file: smtpd_use_tls = yes And in your /etc/postfix/master.cf file, find and uncomment the following stanza: # only used by postfix-tls Reload Postfix. If you telnet to Postfix and issue the EHLO domain.tld command, you should now also see the “250-STARTTLS” line, meaning that Postfix is now taking requests via TLS.
Appendix A main.cf
Appendix B maildroprc
logfile "/var/log/maildrop"
VERBOSE="5"
log "========"
if ( /^X-Spam-Flag: YES/ \ # Watch out for header line added by Spamassassin.
)
{
log "------------------------------------------------------------- Spam general. "
to "Maildir/.Junkmail"
#DELTAG=1
}
|
|
|