Friday, March 12, 2010

Bookmark and Share

June 26, 2009 by Ivan  

Linux Spam Filter With SpamAsassin

Are you tired of being spam in your inbox? If the answer is yes you can reduce spam in your inbox by install SpamAsassin on your mail server. Or you can show this post to your networks/web server administrator to install spamassasin at your mail server.

Here we will use SpamAssasin with Postfix to handle email spam filter. Postfix is a widely used mail transport agent (MTA) used on many popular Unix/Linux systems. And SpamAsassin is one of the apache project is to filter the email. Below is the step to install and configure spamassasin, and this step is for Ubuntu/Debian, for other OS please refer to SpamAsassin official site.

Let’s Start:

1. Install spamasassin and spamc with this command:

sudo apt-get install spamassassin spamc

2. Create specific user for spamAsassin with this command:

groupadd -g 5001 spamd
useradd -u 5001 -g spamd -s /sbin/nologin -d /var/lib/spamassassin spamd
mkdir /var/lib/spamassassin
chown spamd:spamd /var/lib/spamassassin

3. Configure setting in spamAsassin, open /etc/default/spamassassin and then make the setting like below:

ENABLED=1
SAHOME="/var/lib/spamassassin/"
OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir ${SAHOME} -s ${SAHOME}spamd.log"
PIDFILE="${SAHOME}spamd.pid"

4. Configure SpamAsassin rules, open /etc/spamassassin/local.cf and then make the setting like below:

rewrite_header Subject [***** SPAM _SCORE_ *****]
required_score           2.0
#to be able to use _SCORE_ we need report_safe set to 0
#If this option is set to 0, incoming spam is only modified by adding some "X-Spam-" headers and no changes will be made to the body.
report_safe     0
 
# Enable the Bayes system
use_bayes               1
use_bayes_rules         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

5. Start SpamAsassin with this command:

sudo/etc/init.d/spamassassin start


6. Now we need to tell postfix to use SpamAsassin, edit /etc/postfix/master.cf and change the line:

smtp      inet  n       -       -       -       -       smtpd

to

smtp      inet  n       -       -       -       -       smtpd -o content_filter=spamassassin

Then add this:

spamassassin unix -     n       n       -       -       pipe
        user=spamd argv=/usr/bin/spamc -f -e
        /usr/sbin/sendmail -oi -f ${sender} ${recipient}

7. Reload Postfix with this command:

sudo /etc/init.d/postfix reload

That’s it. Hope this post can help you to reduce spam in your inbox. Have a nice day…
Disclaimer: Use these instructions at your own risk. I am not an expert on spam filtering: this set of instructions just gave me what I needed to do my own local spam filtering. If you set it up and it loses you the email clinching a one million dollar contract, I assume no responsibility.

Bookmark and Share

Related Post(s)

Comments

2 Responses to “Linux Spam Filter With SpamAsassin”
  1. Lee Harding says:

    Hi,

    Great post, only thing I’ve noticed, all emails I now send from my server get SPAM prefixed to the subject. I was hoping it would do that to incoming email, not email I send.

    Any ideas? Cheers, Lee.

Trackbacks

Check out what others are saying about this post...
  1. [...] much of the spam that manages to trickle down into your inbox. Yet despite it being pretty easy to setup, I’ve never been all that impressed with its performance [...]



Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!