Faruque Ahmed : MCP, MCSA, MCSE, MCTS, MCIT, CCNA, OCA, OCP, GCP
--------------------------------------------------------
$ sudo apt-get install spamassassin spamc -y
$ sudo adduser spamd --disabled-login
$ sudo nano /etc/default/spamassassin
Find the line:
ENABLED=1
Uncomment it by removing # and change the value from 1 to 0.
ENABLED=0
Find the line:
OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
Change it to include the SpamAssassin user account and log files directory.
OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir /home/spamd/ -s /home/spamd/spamd.log"
3.Find the line:
CRON=0
Change the value from 0 to 1.
CRON=1
SpamAssassin local configuration file
$ sudo mv /etc/spamassassin/local.cf /etc/spamassassin/local.cf.bk
$ sudo nano /etc/spamassassin/local.cf
rewrite_header Subject ***** SPAM _SCORE_ ***** report_safe 0 required_score 5.0 use_bayes 1 use_bayes_rules 1 bayes_auto_learn 1 skip_rbl_checks 0 use_razor2 0 use_dcc 0 use_pyzor 0 ifplugin Mail::SpamAssassin::Plugin::Shortcircuit endif$ sudo nano /etc/postfix/master.cf
smtp inet n - y - - smtpd #smtp inet n - y - 1 postscreen #smtpd pass - - y - - smtpd #dnsblog unix - - y - 0 dnsblog #tlsproxy unix - - y - 0 tlsproxy submission inet n - y - - smtpd--------------------------------------------------------------X--------------------------------------------------------------------------
apt-get install spamassassin spamc
edit # vi /etc/default/spamassassin to configure SpamAssassin as follows.
4. As the next step, we change to CRON=1 at the bottom of this file.
# service spamassassin start
# vi /etc/postfix/master.cf. Then add the following line at the end of the file.
service postfix restart
edit the configuration file # vi /etc/spamassassin/local.cf
# apt-get install dovecot-sieve dovecot-managesieved
# vi /etc/dovecot/conf.d/20-lmtp.conf
------------------------------------------------------X----------------------------------------------------------------------------
Follow these steps to set up an automated spam filter on your Linux Ubuntu web server using SpamAssassin, Dovecot, and Postfix:
Update the package lists and install Postfix, Dovecot, SpamAssassin, and spamc:
sudo apt update
sudo apt install postfix dovecot-imapd dovecot-pop3d spamassassin spamc
Enable the SpamAssassin service to start automatically at boot, and then start the service:
sudo systemctl enable spamassassin
sudo systemctl start spamassassin
Edit the SpamAssassin configuration file /etc/spamassassin/local.cf using a text editor (e.g., nano or vim):
sudo nano /etc/spamassassin/local.cf
Add or modify the following settings in the file:
rewrite_header Subject [SPAM]
required_score 5.0
use_bayes 1
bayes_auto_learn 1
These settings will mark emails with a spam score of 5.0 or higher by adding "[SPAM]" to the subject. You can adjust the required_score value as needed. Save the changes and exit the editor.
Edit the Postfix configuration file /etc/postfix/master.cf:
sudo nano /etc/postfix/master.cf
Add the following lines to the end of the file:
spamassassin unix - n n - - pipe
user=spamd argv=/usr/bin/spamc -f -e
/usr/sbin/sendmail -oi -f ${sender} ${recipient}
Save the changes and exit the editor.
Restart the Postfix service to apply the changes:
sudo systemctl restart postfix
Edit the Dovecot configuration file /etc/dovecot/conf.d/90-sieve.conf:
sudo nano /etc/dovecot/conf.d/90-sieve.conf
Uncomment or add the following lines:
plugin {
sieve = ~/.dovecot.sieve
sieve_default = /etc/dovecot/sieve/default.sieve
sieve_dir = ~/sieve
sieve_global_dir = /etc/dovecot/sieve/global/
}
Save the changes and exit the editor.
Create a default Sieve script /etc/dovecot/sieve/default.sieve:
sudo nano /etc/dovecot/sieve/default.sieve
Add the following content to the file:
require ["fileinto"];
if header :contains "X-Spam-Flag" "YES" {
fileinto "Junk";
}
This script will automatically move messages marked as spam to the "Junk" folder. Save the changes and exit the editor.
Compile the Sieve script:
sudo sievec /etc/dovecot/sieve/default.sieve
Step 7: Restart Dovecot
Restart the Dovecot service to apply the changes:
sudo systemctl restart dovecot
------------------------------------X-----------------------------------------------------------