SpamAssasin. Installation And Setup.

LawrenceLawrence Moderator


SpamAssassin is a computer program used for e-mail spam filtering. SpamAssassin uses a variety of spam-detection techniques, including DNS-based and fuzzy-checksum-based spam detection, Bayesian filtering, external programs, blacklists and online databases. It will save your mailbox from much unwanted spam emails.

For this tutorial we are using Ubuntu 16.04 distribution, however you should be able to use it for all Debian and Ubuntu distributions we offer on Time4VPS.


Update System

First things first. Like always, first of all, we recommend to update your server. It can be done by simply executing:

apt-get update


Installation

After our server is up to date we can start installation. Use apt-get to install Spamassassin and spamc:

apt-get install spamassassin spamc -y

While installing you will get message about kernel, we are using stable kernel version 2.6.32 for OpenVZ, so you do not need to worry about that, just click OK.

Adding User

There are a few steps that has to be taken to make it fully functional. To run Spamassassin you need to create a new user on your VPS. First add the group spams:

groupadd spamd

then add the user spamd with the home directory /var/log/spamassassin:

useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd

then create the directory /var/log/spamassassin:

mkdir /var/log/spamassassin

and change the ownership of the directory to spams:

chown spamd:spamd /var/log/spamassassin


Setting Up

Open the spamassassin config file:

nano /etc/default/spamassassin

Note: If you do not have nano installed on your server, you can do it simply with command:

apt-get install nano

To enable Spamassassin and automatic rule updates in order to get the latest spam filtering rules find the CRON and ENABLED variables and change then to:
ENABLED=1
CRON=1
Now create a variable named SAHOME with the Spamassassin home directory:

SAHOME="/var/log/spamassassin/"

Find and change the OPTIONS variable to:

OPTIONS="--create-prefs --max-children 2 --username spamd \
-H ${SAHOME} -s ${SAHOME}spamd.log"
After setting up is complete we can start the Spamassassin daemon by using the following code:

service spamassassin start


Configuring Postfix
Spamassasin is set up, however emails are still not going through it. To to enabling that, open Postfix config file:

nano /etc/postfix/master.cf

Find the the line

smtp inet n - - - - smtpd

and add the following to the end of the line:

-o content_filter=spamassassin

Now, Postfix will pipe the mail through Spamassassin.

To setup after-queue content filter add the following line 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}
For the changes to take effect restart postfix:

service postfix restart


Configuration

To get the maximum use of Spamassassin you have to create rules. Open the Spamassassin default rules file using:

nano /etc/spamassassin/local.cf

To activate a rules uncomment line by removing the # symbol in beginning of the line. Some line we recommend to uncomment:

rewrite_header Subject [***** SPAM _SCORE_ *****] - To add a spam header to spam mail.

required_score 5.0 - Spamassassin gives a score to each mail after running different tests on it. This line mark the mail as spam if the score is more than the value specified in the rule.

use_bayes 1 - To use bayes theorem to check mails.

bayes_auto_learn 1 - To enable bayes auto learning.

After adding the above details, save the file and restart spam assassin.

service spamassassin restart


Testing

To see if Spamassassin is working, you can check the spamassassin log file using:

nano /var/log/spamassassin/spamd.log

or send the email from an external server and check the mail headers.


Conclusion

Using Spamassassin, it is very easy to protect your mailbox from spammers. The best thing about Spamassassin is that we can create rules by ourselves and manage it.
Tagged:
Sign In or Register to comment.