Skip to content

Instantly share code, notes, and snippets.

Last active December 10, 2020 16:38
What would you like to do?
Spamassassin/SpamD Installation Guide - Ubuntu/Debian

Spamassassin/SpamD Installation Guide

Ubuntu 18/20 or comparable Debian dedicated server


IMPORTANT: This article assumes you do not have amavisd-new installed/running on the same system.

The Ubuntu/Debian amavisd-new package already uses and suggests Spamassassin be installed. If you installed the amavisd-new package, SA was probably already installed and should not need much more tinkering.

Other than checking that the daily cron job is being run to refresh the SA rules (see below), this guide should not be needed. spamd from the Spamassassin package should NOT be a parent process if you are using amavisd-new, BUT should be installed (The spamassassin.service should not be enabled).

Note: Some rules/directives are still observed, while others are not. Amavis has it's own directive/tag system with regards to SA as well.

Further information on Amavis-New and Spamassassin:

The "spamd" User

One reason I wrote these instructions was because every guide I have read includes a bit about creating a "spamd" user.
This is unnecessary.
The default SA debian/ubuntu repository package already creates a debian-spamd user when you install it.
Use that!

  1. Install Spamassassin as stand-alone daemon (spamd) along with it's recommended packages like spamc:

    $ sudo apt-get --install-recommends install spamassassin

  2. Setup spamd options:

    $ sudo systemctl stop spamassassin.service
    $ sudo nano /etc/default/spamassassin

    OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
    OPTIONS="--create-prefs --max-children=5 --helper-home-dir=/var/lib/spamassassin --username=debian-spamd --listen=* --allowed-ips= --syslog=/var/log/spamassassin/spamd.log"


    If your mail server is on the same machine, remove the --listen= and --allowed-ips= flags.
    If it's not, adjust these flags as needed.

  3. Setup logging and logrotate:

    $ sudo mkdir /var/log/spamassassin && sudo chown debian-spamd:debian-spamd /var/log/spamassassin
    $ sudo nano /etc/logrotate.d/spamassassin

    Add the following lines. You MUST include the 'postrotate restart' section as you may get an open file handles 'leak' and run out of drive space:

      /var/log/spamassassin/spamd.log {
          rotate 12
            /bin/systemctl restart spamassassin.service > /dev/null
  4. Get things updated and started:

    Force the daily cron job to execute and refresh rules - check for any errors:

    $ sudo su -
    # /etc/cron.daily/spamassassin
    # systemctl enable spamassassin.service && systemctl start spamassassin.service
    # exit

Complete. You now have a dedicated Spamassassin instance that listens on port 783 on all network interfaces.

As far as networking, the example aboves assumes your email server(s) live on the private IP block (for me this is an AWS /24 local subnet).

The log will be in /var/log/spamassassin and is setup to keep/rotate the past 12 weeks.

Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment