Configuring SpamAssassin on Debian

SpamAssassin is probably the de-facto standard anti-spam solution. If you run a mail server on Debian it is easy to install.

In this guide I will assume you have configured postfix as your mailserver. I also assume that you want to configure a global SpamAssassin instance running as a separate user.

Installation

To install SpamAssassin you need to install the following packages:

apt-get install pyzor razor spamassassin spamc

The packages pyzor and razor are optional, but they offer very valuable additional checks.

Configuring SpamAssassin

For security reasons we want SpamAssassin to run as a separate user. For this reason we create a new user called spamd:

useradd -r -m -d /var/lib/spamd -c 'SpamAssassin Daemon' spamd

Then as this user we need to initialize the pyzor and razor clients:

su - spamd
razor-admin -create
razor-admin -register
pyzor discover

This will create the /var/lib/spamd/.razor and /var/lib/spamd/.pyzor directories with the configuration for these plugins.

Now we still need to configure SpamAssassin itself. There is a nice tool on the web to create a suitable configuration file for you. Make sure you take note of the remarks on the items you need to enable and save the configuration as /etc/spamassassin/local.cf.

The SpamAssassin daemon needs to be configured and enabled by editing /etc/default/spamassassin. Change the OPTIONS line and add -u spamd so it reads as follows:

OPTIONS="--username=spamd --allow-tell --create-prefs --max-children 5 --helper-home-dir"

The option –username=spamd tells the daemon to run as the user spamd, while –allow-tell allows learning through the spamc client. To enable the daemon don’t forget to set ENABLED=1 in /etc/default/spamassassin

Configuring Postfix

Postfix needs to be configured to route the e-mail to spamd, this is done by editing the /etc/postfix/master.cf file and create a new interface.

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

Also the smtp interface must be changed to use spamassassin as a content filter by changing the following line in /etc/postfix/master.cf:

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

Since postfix will pass on the recipient to spamc, we need to tell postfix to deliver the e-mail to each user separately. To do this add the following line to /etc/postfix/main.cf

spamassassin_destination_recipient_limit = 1

After you finished these changes you should start the SpamAssassin daemon and reload postfix to activate the changes:

/etc/init.d/spamassassin start
/etc/init.d/postfix reload

And the test your configuration by sending some e-mail. To verify you should send at least a clean mail and a test spam e-mail. To create a test spam e-mail you can create a mail with the following line somewhere in the body:

  XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

5 thoughts on “Configuring SpamAssassin on Debian”

  1. Hi
    thank your very much for the detailed installation guide. My mail system is now running with spamassassin and everything works fine.

    have a nice evening

    best regards
    Americo

  2. Hi, Thanks a lot!!
    It’s works like a charm on debian 7 (February 2014)
    Moreover I added a little sieve script in order to move my spams directly to the spam folder:
    —- start code —-
    require [“fileinto”];
    # Move spam to spam folder
    if header :contains “X-Spam-Flag” [“YES”] {
    fileinto “spam”;
    stop;
    }
    —- stop code —-

  3. Hi David,
    Thanks for this post.
    Just got this message when trying to create the spamd user.
    # su – spamd
    No passwd entry for user ‘spamd’

    Any suggestion?
    Thanks in advance for your feedback
    Oliver

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.