Contents
1. Install clamav ( anti-virus software )
1.1 Clam AntiVirus Installation
1 |
# pacman -S clamav |
1.2 Virus definition file update settings
1 2 3 4 5 6 7 |
# vim /etc/clamav/freshclam.conf Line 76 Insert "#" at the beginning of the line "DatabaseMirror database.clamav.net", Add "DatabaseMirror db.jp.clamav.net #DatabaseMirror database.clamav.net DatabaseMirror db.jp.clamav.net |
1.3 Virus definition file update
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# freshclam ClamAV update process started at Wed May 8 09:42:44 2024 daily database available for download (remote version: 27268) Time: 1.1s, ETA: 0.0s [========================>] 60.65MiB/60.65MiB Testing database: '/var/lib/clamav/tmp.0e314f9d4b/clamav-fa1d67e0cc8260c72a5df9dd6188faae.tmp-daily.cvd' ... Database test passed. daily.cvd updated (version: 27268, sigs: 2060748, f-level: 90, builder: raynman) main database available for download (remote version: 62) Time: 3.0s, ETA: 0.0s [========================>] 162.58MiB/162.58MiB Testing database: '/var/lib/clamav/tmp.0e314f9d4b/clamav-5d8c95407b03948e3a6b1aa2fbc03bcc.tmp-main.cvd' ... Database test passed. main.cvd updated (version: 62, sigs: 6647427, f-level: 90, builder: sigmgr) bytecode database available for download (remote version: 335) Time: 0.1s, ETA: 0.0s [========================>] 282.94KiB/282.94KiB Testing database: '/var/lib/clamav/tmp.0e314f9d4b/clamav-7866ae45c849c7b8b3618c003fc81d06.tmp-bytecode.cvd' ... Database test passed. bytecode.cvd updated (version: 335, sigs: 86, f-level: 90, builder: raynman) WARNING: Clamd was NOT notified: Can't connect to clamd through /run/clamav/clamd.ctl: No such file or directory |
1 2 |
# systemctl start clamav-freshclam.service # systemctl enable clamav-freshclam.service |
1.4 Clam AntiVirus startup and activation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# systemctl start clamav-daemon.service # systemctl enable clamav-daemon.service Created symlink /etc/systemd/system/multi-user.target.wants/clamav-daemon.service → /usr/lib/systemd/system/clamav-daemon.service. Created symlink /etc/systemd/system/sockets.target.wants/clamav-daemon.socket → /usr/lib/systemd/system/clamav-daemon.socket. # systemctl status clamav-daemon.service ● clamav-daemon.service - Clam AntiVirus userspace daemon Loaded: loaded (/usr/lib/systemd/system/clamav-daemon.service; enabled; preset: disabled) Active: active (running) since Wed 2024-05-08 09:45:07 JST; 2s ago TriggeredBy: ● clamav-daemon.socket Docs: man:clamd(8) man:clamd.conf(5) https://docs.clamav.net/ Main PID: 2441 (clamd) Tasks: 1 (limit: 4630) Memory: 539.4M (peak: 539.4M) CPU: 2.956s CGroup: /system.slice/clamav-daemon.service mq2441 /usr/sbin/clamd --foreground=true May 08 09:45:07 Lepard systemd[1]: Started Clam AntiVirus userspace daemon. May 08 09:45:07 Lepard clamd[2441]: WARNING: Failed to set locale |
1.6 Conducted virus scan
Download a test virus and perform a virus scan
If "stdin: Win.Test.EICAR_HDB-1 FOUND" and "Infected files: 1" are displayed, the program is working properly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# cd /home # curl https://secure.eicar.org/eicar.com.txt | clamscan - % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 68 100 68 0 0 81 0 --:--:-- --:--:-- --:--:-- 81Loading: 1s, ETA: 14s [=> ] 570.00K/8.7 Loading: 11s, ETA: 0s [========================>] 8.69M/8.69M sigs Compiling: 2s, ETA: 0s [========================>] 41/41 tasks stdin: Win.Test.EICAR_HDB-1 FOUND ----------- SCAN SUMMARY ----------- Known viruses: 8692578 Engine version: 1.2.1 Scanned directories: 0 Scanned files: 1 Infected files: 1 Data scanned: 0.00 MB Data read: 0.00 MB (ratio 0.00:1) Time: 14.024 sec (0 m 14 s) Start Date: 2024:05:08 09:48:39 End Date: 2024:05:08 09:48:53 |
1.7 Deployment of virus scan auto-execution scripts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# mkdir -p /srv/system Create clamscan.sh in /srv/system with the following contents # vim /srv/system/clamscan.sh #!/bin/bash PATH=/usr/bin:/bin # excludeopt setup excludelist=/srv/system/clamscan.exclude if [ -s $excludelist ]; then for i in `cat $excludelist` do if [ $(echo "$i"|grep \/$) ]; then i=`echo $i|sed -e 's/^\([^ ]*\)\/$/\1/p' -e d` excludeopt="${excludeopt} --exclude-dir=$i" else excludeopt="${excludeopt} --exclude=$i" fi done fi # signature update freshclam # virus scan clamscan --recursive --remove ${excludeopt} / |
Grant execution permission to scripts
1 |
# chmod 700 /srv/system/clamscan.sh |
1.8 Virus scan exclusion directory settings
1 2 |
# echo "/sys/" >> /srv/system/clamscan.exclude # echo "/proc/" >> /srv/system/clamscan.exclude |
Exclude sys and proc directories.
1.9 Scheduled virus scan execution
Install cronie to make crontab available
1 2 |
# pacman -S cronie # systemctl enable --now cronie.service |
To temporarily use vim as a text editor in crontab
1 2 |
# export EDITOR=vim # export VISUAL=vim |
To use vim as a text editor in a permanent crontab
Symbolically link with vi
1 |
# ln -s /usr/bin/vim /usr/bin/vi |
1 2 |
# crontab -e 0 1 * * * /srv/system/clamscan.sh > /dev/null 2>&1 |
Run a trial script and do a full scan (takes a while)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# /srv/system/clamscan.sh ----------- SCAN SUMMARY ----------- Known viruses: 8692578 Engine version: 1.2.1 Scanned directories: 6345 Scanned files: 70141 Infected files: 0 Data scanned: 4455.86 MB Data read: 3225.58 MB (ratio 1.38:1) Time: 814.243 sec (13 m 34 s) Start Date: 2024:05:08 09:58:45 End Date: 2024:05:08 10:12:20 |
2. Mail Server (Postfix)
2.1 Installing Postfix
Install Postfix and build an SMTP server
1 |
# pacman -S postfix |
Postfix version check
1 2 3 |
# postconf | grep mail_version mail_version = 3.9 milter_macro_v = $mail_name $mail_version |
2.2 Register Postfix to the service
1 2 3 4 |
# systemctl enable postfix.service # systemctl is-enabled postfix.service enabled |
2.3 Edit postfix configuration file
Backup postfix configuration files, main.cf and master.cf files
1 2 |
# cp -p /etc/postfix/main.cf `date '+/etc/postfix/main.cf.%Y%m%d'` # cp -p /etc/postfix/master.cf `date '+/etc/postfix/master.cf.%Y%m%d'` |
To prevent unauthorized mail relay, configure Postfix to require authentication for outgoing mail as well, using Dovecot's SASL function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# vim /etc/postfix/main.cf Per Line 100 : add #myhostname = virtual.domain.tld myhostname = mail.[domain] Per Line 107 : Add domain name #mydomain = domain.tld mydomain = [domain] Per Line 122 : Uncomment myorigin = $mydomain Per Line 136 : Uncomment inet_interfaces = all Per Line 184 : Uncomment #mydestination = $myhostname, localhost.$mydomain, localhost mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain Per Line 227 : Uncomment local_recipient_maps = unix:passwd.byname $alias_maps Per Line 272 : Uncomment mynetworks_style = subnet Per Line 289 : add #mynetworks = 168.100.189.0/28, 127.0.0.0/8 #mynetworks = $config_directory/mynetworks #mynetworks = hash:/etc/postfix/network_table mynetworks = 192.168.11.0/24, 127.0.0.0/8 ←192.168.11.0/24 to suit your environment Per Line 445 : Uncomment Set the mail storage format. #home_mailbox = Mailbox home_mailbox = Maildir/ Per Line 453 : add mail_spool_directory = /var/spool/mail Per Line 581 : add #smtpd_banner = $myhostname ESMTP $mail_name #smtpd_banner = $myhostname ESMTP $mail_name ($mail_version) smtpd_banner = $myhostname ESMTP unknown Add the following to the last line # Limit send/receive mail size to 10M message_size_limit = 10485760 # Limit mailbox size to 1G mailbox_size_limit = 1073741824 # SMTP-Auth Settings smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous smtpd_sasl_local_domain = $myhostname smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject |
2.4 Release SMTP port (port 25)
1 2 3 |
# ufw allow smtp # ufw reload |
2.5 Start Postfix
1 2 3 |
# newaliases # systemctl enable --now postfix # systemctl start postfix |
3. Mail Server(Dovecot)
3.1 Dovecot Installation
1 |
# pacman -S dovecot |
3.2 Edit dovecot.conf file
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# mkdir /etc/dovecot # cp /usr/share/doc/dovecot/example-config/dovecot.conf /etc/dovecot/dovecot.conf # cp -R /usr/share/doc/dovecot/example-config/conf.d /etc/dovecot/ # vim /etc/dovecot/dovecot.conf Per Line 25 : confirmation # protocols = imap pop3 lmtp submission protocols = imap pop3 Per Line 30 : Uncomment # Remove [::] if listening for IPv4 only listen = *, :: |
3.3 Edit 10-auth.conf file
1 2 3 4 5 6 7 8 9 |
# vim /etc/dovecot/conf.d/10-auth.conf Line 10 : Confirmation If plain text authentication is also allowed #disable_plaintext_auth = yes disable_plaintext_auth = no Line 100 : add auth_mechanisms = plain login |
3.4 Edit 10-mail.conf file
1 2 3 4 |
# vim /etc/dovecot/conf.d/10-mail.conf Line 31 : add mail_location = maildir:~/Maildir |
3.5 Edit 10-master.conf file
1 2 3 4 5 6 7 8 9 |
# vim /etc/dovecot/conf.d/10-master.conf Line 110-112 : Uncommented and added # Postfix smtp-auth unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix } |
3.6 Edit 10-ssl.conf file
1 2 3 4 5 6 7 8 |
# vim /etc/dovecot/conf.d/10-ssl.conf Per Line 7 : add ssl = no Line 12-13 : comment-out #ssl_cert = </etc/ssl/certs/dovecot.pem #ssl_key = </etc/ssl/private/dovecot.pem |
3.7 Register dovecot as a service and start it
1 2 3 4 |
# systemctl enable dovecot.service # systemctl is-enabled dovecot.service enabled # systemctl start dovecot.service |
3.8 Permission port opening for POP/IMAP service in UFW
POP is [110/TCP], IMAP is [143/TCP].
1 2 3 |
# ufw allow pop3 # ufw allow imap # ufw reload |
4. Create mail user and check operation
4.1 advance preparation
①Pre-processing for new users
When a new user is added, the system is configured to automatically send and receive e-mail.
1 2 3 4 |
# mkdir -p /etc/skel/Maildir/{new,cur,tmp} # chmod -R 700 /etc/skel/Maildir/ # echo "~/Maildir/"> /etc/skel/.forward # chmod 600 /etc/skel/.forward |
②Mail environment preprocessing for existing users(huong)
Configure already created users to be able to send and receive mail.
1 2 3 4 |
# mkdir -p /home/huong/Maildir/{new,cur,tmp} # chown -R huong:huong /home/huong/Maildir/ # chmod 700 /home/huong/Maildir # chmod 700 /home/huong/Maildir/{new,cur,tmp} |
4.2 User Account Creation
Mail client installation
1 2 |
# pacman -S s-nail # echo 'export MAIL=$HOME/Maildir' >> /etc/profile.d/mail.sh |
Add user [linux]
1 2 3 4 5 6 |
# useradd -m linux # passwd linux Change password for user linux. New password: Retype new password: passwd: all authentication tokens updated successfully. |
4.3 operation check ①
Log in as an email user and send a test email.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# su - linux $ mail linux@localhost Subject: Test Mail test mail ← "Ctrl+D" to end the text ------- (Preliminary) Envelope contains: To: linux@localhost Subject: Test Mail Send this message [yes/no, empty: recompose]? y Check your e-mail $ mail mail version v14.9.24. Type `?' for help /home/linux/Maildir: 1 message 1 new ?N 1 linux@korodes.com 2023-12-19 09:42 17/514 Test Mail ? 1 [-- Message 1 -- 17 lines, 514 bytes --]: Date: Tue, 19 Dec 2023 09:42:30 +0900 To: linux@localhost Subject: Test Mail Message-Id: <20231219004230.6E33F10053C@mail.korodes.com> From: linux@korodes.com test mail ? q Enter "q" to exit Held 1 message in /home/linux/Maildir You have mail in /home/linux/Maildir |
4.4 operation check ②
Set up and confirm your account in Mozilla Thunderbird.
This time, we will use the general user "huong" to set up the account.
① Start Thunderbird, click "Tools", and then click "Account Settings".
②「Account Actions」「Add Mail Account」
③"Your full name" is an optional name
Email addtess" is "huong@korodes.com" added earlier
"Password" is the password for user huong
Enter each and click "Configure manually".
④Set "INCOMMING SERVER" and "OUTGOING SERVER" as shown below and click "Re-test".
⑤The following settings were found by probinfg the given server
After clicking "Done," the following "Warning" appears, but there is no problem, so click "Confirm"
⑥Click "Finish" when "Account syccessfuly created" is displayed.
Mail Server : Postfix + Clamav + clamav-milter+SpamAssassin
1. Real-time scanning of email
①clamav-milter configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# vim /etc/clamav/clamav-milter.conf Per Line 22-23 : add # Default: no default #MilterSocket /run/clamav-milter/clamav-milter.socket #MilterSocket inet:7357 MilterSocket /run/clamav/clamav-milter.sock ← Specify the UNIX socket name for clamav-milter MilterSocketMode 666 ← Specify UNIX socket access rights for clamav-milter Per Line 36 : FixStaleSocket yes Per Line 69 : confirmation PidFile /run/clamav/clamav-milter.pid Per Line 74 : confirmation TemporaryDirectory /tmp Per Line 98 : add # Default: no default #ClamdSocket tcp:scanner.mydomain:7357 ClamdSocket unix:/run/clamav/clamd.ctl Per Line 171 : add # Action to be performed on infected messages # Default: Quarantine #OnInfected Quarantine OnInfected Blackhole ← Destroy virus-infected e-mails. Per Line 193 : add # Note that while "Replace" can potentially break DKIM signatures, "Add" may # confuse procmail and similar filters. # Default: no #AddHeader Replace AddHeader Yes ← Outputs a message in the mail header stating that a virus check has been performed. Per Line 253 : Uncomment # Default: LOG_LOCAL6 LogFacility LOG_MAIL ← Log output destination to mail log |
MilterSocketMode 666 ← Specify UNIX socket access rights for clamav-milter
All I see on the internet is "MilterSocketMode 660", but with 660, clamav-milter does not start and I get an error.
However, there is a problem because anyone can read and write in 666. I don't know how to solve this problem
➁Create /etc/systemd/system/clamav-milter.service
1 2 3 4 5 6 7 8 9 10 11 12 |
# vim /etc/systemd/system/clamav-milter.service [Unit] Description='ClamAV Milter' After=clamd-daemon.service [Service] Type=forking ExecStart=/usr/bin/clamav-milter --config-file /etc/clamav/clamav-milter.conf [Install] WantedBy=multi-user.target |
➂clamav-milter startup and auto-startup settings
1 2 3 4 |
# systemctl start clamav-milter # systemctl enable clamav-milter Created symlink /etc/systemd/system/multi-user.target.wants/clamav-milter.service → /usr/lib/systemd/system/clamav-milter.service. |
④Postfix and clamav-milter integration settings
Edit Postfix configuration file
1 2 3 4 5 |
# vim /etc/postfix/main.cf Add the following milter_default_action = tempfail smtpd_milters = unix:/run/clamav/clamav-milter.sock non_smtpd_milters = unix:/run/clamav/clamav-milter.sock |
⑤Add postfix user to clamav group
1 |
# usermod -G clamav -a postfix |
1 |
# systemctl restart clamav-milter |
⑥Postfix Settings Reflected
1 |
# systemctl restart postfix |
⑦TCheck with hunderbird
I sent a blank email to myself in Thunderbird, and in the header display of the received email, I see the following
"X-Virus-Scanned: clamav-milter 1.2.1 at Lepard"
Try sending yourself an email with the body of the email "X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*" and confirm that the email is discarded and never received
2. Email spam protection
2.1 SpamAssassin, spamass-milter, and postfix settings
①SpamAssassin installation
1 |
# pacman -S spamassassin |
➁spamass-milter installation
spamass-milter is available in the aur (arch user repository) software package suite and can be installed using yay.
There is a lot of information on the web about how to install and use yay, so I will skip this section.
1 |
$ yay -S spamass-milter |
➂Start SpamAssassin
1 2 3 |
# sa-update # systemctl start spamassassin # systemctl enable spamassassin |
1 |
# systemctl status spamassassin |
If you get the following error
"deprecated method; size() is an alias of "UDPsize()" at /usr/share/perl5/vendor_perl/Mail/SpamAssassin/DnsResolver.pm line 600."
"/usr/share/perl5/vendor_perl/Mail/SpamAssassin/DnsResolver.pm" Change line 600
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# vim /usr/share/perl5/vendor_perl/Mail/SpamAssassin/DnsResolver.pm if ($packet) { # RD flag needs to be set explicitly since Net::DNS 1.01, Bug 7223 $packet->header->rd(1); # my $udp_payload_size = $self->{res}->udppacketsize; my $udp_payload_size = $self->{conf}->{dns_options}->{edns}; if ($udp_payload_size && $udp_payload_size > 512) { # dbg("dns: adding EDNS ext, UDP payload size %d", $udp_payload_size); $packet->edns->size($udp_payload_size); } } ↓ if ($packet) { # RD flag needs to be set explicitly since Net::DNS 1.01, Bug 7223 $packet->header->rd(1); # my $udp_payload_size = $self->{res}->udppacketsize; my $udp_payload_size = $self->{conf}->{dns_options}->{edns}; if ($udp_payload_size && $udp_payload_size > 512) { # dbg("dns: adding EDNS ext, UDP payload size %d", $udp_payload_size); # $packet->edns->size($udp_payload_size); if ($packet->edns->can('udpsize')) { # since Net::DNS 1.38 $packet->edns->udpsize($udp_payload_size); } else { $packet->edns->size($udp_payload_size); } } } |
④SpamAssassin Settings
1 2 3 4 |
# vim /etc/mail/spamassassin/v310.pre Per Line 24 : Remove # at the beginning of the line loadplugin Mail::SpamAssassin::Plugin::DCC |
⑤SpamAssassin configuration file update script
Install the wget command beforehand.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# cd /srv/system # vim spamassassin-update.sh Describe the following contents #!/bin/bash cd /etc/mail/spamassassin wget -q https://github.com/kittyfreak/spamassassin_user_prefs/archive/refs/heads/main.zip [ $? -ne 0 ] && exit unzip main.zip >/dev/null 2>&1 [ $? -ne 0 ] && exit rm -f main.zip mv spamassassin_user_prefs-main/user_prefs . rm -rf spamassassin_user_prefs-main diff user_prefs user_prefs.org > /dev/null 2>&1 if [ $? -ne 0 ]; then cp user_prefs local.cf echo "report_safe 0" >> local.cf echo "rewrite_header Subject ***SPAM***" >> local.cf # Restart SpamAssassin if [ -f /usr/bin/vendor_perl/spamassassin ]; then /usr/bin/vendor_perl/spamassassin restart > /dev/null else systemctl restart spamassassin > /dev/null fi fi cp user_prefs user_prefs.org |
Grant execute permission to the spamassassin-update script and run it
1 2 |
# chmod 700 /srv/system/spamassassin-update.sh # /srv/system/spamassassin-update.sh |
Confirm that the SpamAssassin configuration file (local.cf) has been created in the /etc/mail/spamassassin directory with the same date
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# ls -l /etc/mail/spamassassin total 1776 -rw-r--r-- 1 root root 1649 Jul 27 2023 init.pre -rw-r--r-- 1 root root 500636 May 8 10:52 local.cf -rw-r--r-- 1 root root 127072 May 8 10:49 main.zip.1 -rw-r--r-- 1 root root 127072 May 8 10:52 main.zip.2 drwx------ 3 root root 4096 May 8 10:45 sa-update-keys -rw-r--r-- 1 root root 500588 Apr 30 2023 user_prefs -rw-r--r-- 1 root root 500588 May 8 10:55 user_prefs.org -rw-r--r-- 1 root root 2262 May 8 10:47 v310.pre -rw-r--r-- 1 root root 1168 Jul 27 2023 v312.pre -rw-r--r-- 1 root root 2416 Jul 27 2023 v320.pre -rw-r--r-- 1 root root 1237 Jul 27 2023 v330.pre -rw-r--r-- 1 root root 1020 Jul 27 2023 v340.pre -rw-r--r-- 1 root root 1315 Jul 27 2023 v341.pre -rw-r--r-- 1 root root 1475 Jul 27 2023 v342.pre -rw-r--r-- 1 root root 1266 Jul 27 2023 v343.pre -rw-r--r-- 1 root root 1482 Jul 27 2023 v400.pre |
Set up cron to automatically run a script daily that updates the SpamAssassin configuration file
1 2 |
# crontab -e 0 2 * * * /srv/system/spamassassin-update.sh > /dev/null 2>&1 |
⑥spamass-milter startup and automatic startup settings
1 2 3 4 |
# systemctl start spamass-milter # systemctl enable spamass-milter Created symlink /etc/systemd/system/multi-user.target.wants/spamass-milter.service → /usr/lib/systemd/system/spamass-milter.service. |
⑦Postfix and spamass-milter integration settings
1 2 3 4 5 6 |
# vim /etc/postfix/main.cf Add the following milter_default_action = tempfail smtpd_milters = unix:/var/run/clamav-milter/clamav-milter.socket,unix:/var/spool/postfix/spamass/spamass.sock non_smtpd_milters = unix:/var/run/clamav-milter/clamav-milter.socket,unix:/var/spool/postfix/spamass/spamass.sock |
⑧Restart postfix
1 |
# systemctl restart postfix |
⑨Procmail Installation and Configuration
procmail installation
procmail is in the AUR (Arch User Repository) software package group, so use the AUR (Arch User Repository) helper yay to install it.
1 |
$ yay -S procmail |
Create procmail configuration file
1 2 3 4 5 6 7 8 |
# vim /etc/procmailrc SHELL=/bin/bash PATH=/usr/bin:/bin DROPPRIVS=yes MAILDIR=$HOME/Maildir DEFAULT=$MAILDIR/ LOGFILE=$HOME/.procmail.log # Log output destination VERBOSE=ON # Detailed log output |
Create procmail log rotation configuration file
1 2 3 4 5 6 |
# vim /etc/logrotate.d/procmail /home/*/.procmail.log { missingok nocreate notifempty } |
⑩Postfix and Procmail integration settings
1 2 3 4 5 6 |
# vim /etc/postfix/main.cf Per Line 475 : add #mailbox_command = /some/where/procmail #mailbox_command = /some/where/procmail -a "$EXTENSION" mailbox_command = /usr/bin/procmail ← Addition (to be linked to Procmail) |
1 2 3 4 5 6 7 8 9 10 11 |
# vim /etc/postfix/master.cf ●Per Line 12 Add "#" to the beginning of line 12 and add SpamAssassin setting to line 13 # smtp inet n - n - - smtpd smtp inet n - n - - smtpd -o content_filter=spamassassin ●Add to last line spamassassin unix - n n - - pipe user=nobody argv=/usr/bin/vendor_perl/spamc -e /usr/bin/sendmail -oi -f ${sender} ${recipient} |
Postfix Settings Reflected
1 |
# systemctl restart postfix |
2.2 Spam Mail Filtering Settings
Mail marked as spam in the mail header by SpamAssassin will be delivered to a spam-only mailbox, while other mail will be delivered to a normal mailbox.
①Create a dedicated spam mailbox
For existing users, add a spam-only mailbox to their mailboxes.
For new users, a spam-only mailbox will be automatically created when a user is added.
➁Created script to create spam-only mailboxes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# vim spamfolder-create Describe the following content #!/bin/bash for user in `ls /home` do id -u $user > /dev/null 2>&1 if [ $? -eq 0 ] && [ ! -d /home/$user/Maildir/.Spam/new ]; then mkdir -p /home/$user/Maildir/.Spam/new mkdir -p /home/$user/Maildir/.Spam/cur mkdir -p /home/$user/Maildir/.Spam/tmp chmod -R 700 /home/$user/Maildir/.Spam chown -R $user. /home/$user/Maildir/.Spam echo $user fi done |
Run script to create spam-only mailboxes
1 2 3 |
# bash spamfolder-create huong linux |
➂Measures for new users
Automatic spam-only mailbox creation when adding new users
1 2 |
# mkdir -p /etc/skel/Maildir/.Spam/{new,cur,tmp} # chmod -R 700 /etc/skel/Maildir/.Spam |
④spam filtering
Emails identified as spam by SpamAssassin are delivered to a spam-only mailbox.
1 2 3 4 5 6 |
# vim /etc/procmailrc Add the following to the end # Emails identified as spam by SpamAssassin are delivered to a spam-only mailbox :0 *^X-Spam-Flag: YES $HOME/Maildir/.Spam/ |
⑤spamass-milter confirmation
When you send a blank email to yourself, the following message is appended to the header of the received email
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on Lepard
⑥Spam check confirmation
Send yourself an email with the body of the email "XJSC4JDBQADN1.NSBN32IDNENGTUBE-STANDARD-ANTI-UBE-TEST-EMAILC.34X" and make sure the email is not delivered and is sorted into the Spam folder