Tag Archives: Debian

Articles that contain Debian specific instructions.

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.


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: