Skip to content

Instantly share code, notes, and snippets.

@bmatthewshea
Last active December 10, 2020 16:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bmatthewshea/2acd4126b163216f2cefd605609befc8 to your computer and use it in GitHub Desktop.
Spamassassin/SpamD Installation Guide - Ubuntu/Debian

Spamassassin/SpamD Installation Guide

Ubuntu 18/20 or comparable Debian dedicated server

amavisd-new

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 local.cf 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:
https://help.ubuntu.com/community/PostfixAmavisNew#Spamassassin
https://www.ijs.si/software/amavisd/amavisd-new-docs.html


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

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

    Change:
    CRON=0
    To:
    CRON=1

    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 {
          copytruncate
          rotate 12
          weekly
          compress
          missingok
          postrotate
            /bin/systemctl restart spamassassin.service > /dev/null
          endscript
      }
    
  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 10.0.0.0/8 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