In one of our previous articles we explained how one can setup and configure a simple but powerful mail server with Postfix, Dovecot, SASL and virtual users in a Debian Squeeze VPS.
In the following article we’re going to implement SpamAssassin into the mail server setup so that it can be used to identify and tag spam email messages.
1.) Update the system
Before proceeding with the setup we need to make sure our Debian Box is fully up to date by issuing:
# apt-get update
# apt-get upgrade
2.) Install SpamAssassin
once the upgrade is completed install ‘SpamAssassin’ by executing:
# apt-get install spamc spamassassin
3.) Setup unprivileged user/group for SpamAssassin
by default spamassassin will run under the ‘root’ user and running it like that is not as secure as it can be, so to make it more secure we should run it under different unprivileged user/group.
# groupadd -g 5555 spamd # useradd -u 5555 -g spamd -s /sbin/nologin -d /usr/local/spamassassin spamd # mkdir -p /usr/local/spamassassin/log # chown spamd:spamd -R /usr/local/spamassassin
4.) Setup SpamAssassin daemon options
edit the ‘/etc/default/spamassassin’ configuration file and make it looks like the one below:
# /etc/default/spamassassin # Duncan Findlay # WARNING: please read README.spamd before using. # There may be security risks. # Change to one to enable spamd ENABLED=1 SPAM_HOME="/usr/local/spamassassin" # Options # See man spamd for possible options. The -d option is automatically added. # SpamAssassin uses a preforking model, so be careful! You need to # make sure --max-children is not set to anything higher than 5, # unless you know what you're doing. OPTIONS="--create-prefs --max-children 5 --helper-home-dir ${SPAM_HOME} --username spamd -s ${SPAM_HOME}/log/spamd.log" # Pid file # Where should spamd write its PID to file? If you use the -u or # --username option above, this needs to be writable by that user. # Otherwise, the init script will not be able to shut spamd down. PIDFILE="${SPAM_HOME}/spamd.pid" # Set nice level of spamd #NICE="--nicelevel 15" # Cronjob # Set to anything but 0 to enable the cron job to automatically update # spamassassin's rules on a nightly basis CRON=0
5.) Configure SpamAssassin
the next think we need to do is to configure spamassassin. you do this by editing the ‘/etc/spamassassin/local.cf’ and changing/adding the following:
rewrite_header Subject *****SPAM***** required_score 3.0 report_safe 0 use_bayes 1 # Enable Bayes auto-learning bayes_auto_learn 1 # Enable or disable network checks skip_rbl_checks 0 use_razor2 0 use_dcc 0 use_pyzor 0
6.) Configure Postfix to use SpamAssassin
to tell postfix to use spamassassin edit /etc/postfix/master.cf and change the following:
this:
smtp inet n - - - - smtpd
with this:
smtp inet n - - - - smtpd -o content_filter=spamassassin
and add the following to the end of the file:
spamassassin unix - n n - - pipe user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
finally, restart the services by:
/etc/init.d/spamassassin restart
/etc/init.d/postfix restart
and that’s it.
Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert linux admins to install this for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.
thanks! i just followed these instructions and it seems to be working. :)