Contents
- 1. Clamav ( anti-virus software )
- 1.1 Clam AntiVirus Install
- 1.2 Edit Clam AntiVirus configuration file
- 1.3 Virus definition file update settings
- 1.4 Update virus definition files
- 1.5 Start Clam AntiVirus
- 1.6 Conducted virus scan
- 1.7 Deployment of virus scan auto-execution scripts
- 1.8 Exclude sys and proc directories.
- 1.9 Scheduled virus scan execution
- 2. Mail server(Postfix)
- 3. Mail server(Dovecot)
- 4.Create mail user and check operation
- Mail Server : Postfix + Clamav + clamav-milter+SpamAssassin
1. Clamav ( anti-virus software )
1.1 Clam AntiVirus Install
1 |
# dnf -y install clamav clamd clamav-update |
1.2 Edit Clam AntiVirus configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# vi /etc/clamd.d/scan.conf ●Line 14 # Default: disabled LogFile /var/log/clamd.scan ← Uncomment ●Line 77 # Default: disabled PidFile /run/clamd.scan/clamd.pid ← Uncomment ●Line 97 : add # Path to a local socket file the daemon will listen on. # Default: disabled (must be specified by a user) #LocalSocket /run/clamd.scan/clamd.sock LocalSocket /var/run/clamd.scan/clamd.sock ●Line 227 # Run as another user (clamd must be started by root for this option to work) # Default: don't drop privileges #User clamscan ← Add # at the beginning of the line and comment it out (to make it work with root privileges) |
1.3 Virus definition file update settings
1 2 3 4 5 6 7 8 9 |
# vi /etc/freshclam.conf ●Line 75 : Comment out and add under it #DatabaseMirror database.clamav.net DatabaseMirror db.jp.clamav.net ●Per line 151 Add "NotifyClamd /etc/clamd.d/scan.conf" #NotifyClamd /path/to/clamd.conf NotifyClamd /etc/clamd.d/scan.conf |
1.4 Update virus definition files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# freshclam ClamAV update process started at Sat Apr 27 09:38:04 2024 daily database available for download (remote version: 27257) Time: 0.8s, ETA: 0.0s [========================>] 60.60MiB/60.60MiB Testing database: '/var/lib/clamav/tmp.f446e0b8b4/clamav-37809f63064a9d1f33208c30c0dbe38a.tmp-daily.cvd' ... Database test passed. daily.cvd updated (version: 27257, sigs: 2060183, f-level: 90, builder: raynman) main database available for download (remote version: 62) Time: 1.7s, ETA: 0.0s [========================>] 162.58MiB/162.58MiB Testing database: '/var/lib/clamav/tmp.f446e0b8b4/clamav-dedab823925af27b16894bd366d1bacc.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.f446e0b8b4/clamav-4ec1e5064460ba2cbfd8debd4f8369ff.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 /var/run/clamd.scan/clamd.sock: No such file or directory |
1.5 Start Clam AntiVirus
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 |
# systemctl start clamd@scan ← clamd start # systemctl enable clamd@scan ← Automatic clamd startup configuration Created symlink /etc/systemd/system/multi-user.target.wants/clamd@scan.service → /usr/lib/systemd/system/clamd@.service. # systemctl is-enabled clamd@scan enabled # systemctl status clamd@scan ← operation check ● clamd@scan.service - clamd scanner (scan) daemon Loaded: loaded (/usr/lib/systemd/system/clamd@.service; enabled; preset: disabled) Drop-In: /usr/lib/systemd/system/service.d mq10-timeout-abort.conf Active: active (running) since Sat 2024-04-27 09:39:41 JST; 32s ago Docs: man:clamd(8) man:clamd.conf(5) https://www.clamav.net/documents/ Main PID: 3330 (clamd) Tasks: 2 (limit: 4595) Memory: 1.2G (peak: 1.2G) CPU: 18.183s CGroup: /system.slice/system-clamd.slice/clamd@scan.service mq3330 /usr/sbin/clamd -c /etc/clamd.d/scan.conf Apr 27 09:39:41 Lepard clamd[3330]: ELF support enabled. Apr 27 09:39:41 Lepard clamd[3330]: Mail files support enabled. Apr 27 09:39:41 Lepard systemd[1]: Started clamd@scan.service - clamd scanner (scan) daemon. Apr 27 09:39:41 Lepard clamd[3330]: OLE2 support enabled. Apr 27 09:39:41 Lepard clamd[3330]: PDF support enabled. Apr 27 09:39:41 Lepard clamd[3330]: SWF support enabled. Apr 27 09:39:41 Lepard clamd[3330]: HTML support enabled. Apr 27 09:39:41 Lepard clamd[3330]: XMLDOCS support enabled. |
1.6 Conducted virus scan
Download a test virus and perform a virus scan
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# cd / # wget https://secure.eicar.org/eicar.com.txt # clamscan --infected --remove --recursive / /eicar.com.txt: Win.Test.EICAR_HDB-1 FOUND /eicar.com.txt: Removed. ----------- SCAN SUMMARY ----------- Known viruses: 8692013 Engine version: 1.0.5 Scanned directories: 30724 Scanned files: 89154 Infected files: 1 Total errors: 1125 Data scanned: 5120.13 MB Data read: 2606.60 MB (ratio 1.96:1) Time: 637.374 sec (10 m 37 s) Start Date: 2024:04:27 09:43:18 End Date: 2024:04:27 09:53:55 |
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 /var/www/system clamscan.sh Create in /var/www/system with the following contents # vi /var/www/system/clamscan.sh #!/bin/bash PATH=/usr/bin:/bin # excludeopt setup excludelist=/var/www/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 /var/www/system/clamscan.sh |
1.8 Exclude sys and proc directories.
1 2 |
# echo "/sys/" >> /var/www/system/clamscan.exclude # echo "/proc/" >> /var/www/system/clamscan.exclude |
Exclude sys and proc directories.
1.9 Scheduled virus scan execution
1 2 |
# crontab -e 0 1 * * * /var/www/system/clamscan.sh > /dev/null 2>&1 |
Run a trial script and do a full scan (takes a while)
1 |
# /var/www/system/clamscan.sh |
2. Mail server(Postfix)
2.1 Postfix Install
Install Postfix and build an SMTP server
1 |
# dnf -y install postfix |
Check if Postfix is installed
1 2 |
# rpm -qa | grep postfix postfix-3.8.5-4.fc40.x86_64 |
2.2 Register Postfix to the service
1 2 3 4 |
# systemctl enable postfix.service Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/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 |
# vi /etc/postfix/main.cf ●Line 100 : Add Host name #myhostname = virtual.domain.tld myhostname = mail.[Domain name] ●Line 107 : Add Domain #mydomain = domain.tld mydomain = <Domain name> ●Line 122 : Uncomment myorigin = $mydomain ●Per Line136 : Uncomment inet_interfaces = all ●Per Line139 : Comment out #inet_interfaces = localhost ●Comment out around line 187 and uncomment line 188 #mydestination = $myhostname, localhost.$mydomain, localhost mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ●Per line 294 : 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 448 : Uncomment Set the mail storage format #home_mailbox = Mailbox home_mailbox = Maildir/ ●Per line456 : add #mail_spool_directory = /var/mail mail_spool_directory = /var/spool/mail ●Per line 603 : 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 smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous smtpd_sasl_local_domain = $mydomain smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject |
2.4 Release SMTP port (port 25)
1 2 3 4 |
# firewall-cmd --add-service=smtp --permanent success # firewall-cmd --reload success |
2.5 Postfix restart
1 2 |
# systemctl enable --now postfix # systemctl start postfix |
3. Mail server(Dovecot)
3.1 Dovecot Install
1 |
# dnf -y install dovecot |
3.2 Edit dovecot.conf file
1 2 3 4 5 6 7 8 9 10 11 |
# cp -p /etc/dovecot/dovecot.conf `date '+ /etc/dovecot/dovecot.conf.%Y%m%d'` # vi /etc/dovecot/dovecot.conf ●Per Line25 : Add # protocols = imap pop3 lmtp protocols = imap pop3 ●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 |
# vi /etc/dovecot/conf.d/10-auth.conf ●Line 10 : Uncomment and change If plain text authentication is also allowed disable_plaintext_auth = no ●Line 100 : Add auth_mechanisms = plain login |
3.4 Edit 10-mail.conf file
1 2 3 4 |
# vi /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 |
# vi /etc/dovecot/conf.d/10-master.conf ●Line 110-112 : Uncomment and add # 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 |
# vi /etc/dovecot/conf.d/10-ssl.conf Line 9 Change ssl = yes |
3.7 Register dovecot as a service and start it
1 2 3 4 5 |
# systemctl enable dovecot.service Created symlink /etc/systemd/system/multi-user.target.wants/dovecot.service → /usr/lib/systemd/system/dovecot.service. # systemctl is-enabled dovecot.service Enabled # systemctl start dovecot.service |
3.8 Permission port opening for POP/IMAP service with firewalld
POP : [110/TCP], IMAP : [143/TCP]
1 2 3 |
# firewall-cmd --permanent --add-service=pop3 # firewall-cmd --permanent --add-service=imap # firewall-cmd --reload |
4.Create mail user and check operation
4.1 advance preparation
①Pretreatment for new users
When a new user is added, set up the system 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 pre-processing for existing users
Configure the already created users(huong) to be able to send and receive e-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 |
# dnf -y install s-nail # echo 'export MAIL=$HOME/Maildir' >> /etc/profile.d/mail.sh |
Add user [linux]
1 2 3 4 5 6 |
# useradd linux # passwd linux Changing 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 |
# su - linux $ mail linux@localhost Subject: Test Mail To: linux@localhost test mail ^D ← "Ctrl+D" to end the text ------- (Preliminary) Envelope contains: To: linux@localhost Subject: Test Mail Send this message [yes/no, empty: recompose]? y sendmail: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol postdrop: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol |
Check your email
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ mail s-nail version v14.9.24. Type `?' for help /home/linux/Maildir: 1 message 1 new ?N 1 linux@korodes.com 2024-04-27 10:45 17/518 "Test Mail " & 1 [-- Message 1 -- 17 lines, 518 bytes --]: Date: Sat, 27 Apr 2024 10:45:02 +0900 To: linux@localhost Subject: Test Mail Message-Id: <20240427014502.3E32510CEFE3@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 (for OS user huong as mail user)
①Start Thunderbird
「Tools」「Account Settings」
②「Account Actions」「Add Mail Account」
③Your full name : Any name
Email addtess : huong@korodes.com
Password : Password for huong
Click on "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" Displayed
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 e-mails
①clamav-milter Install
Virus checks are performed on the mail server side using Clam AntiVirus.
The mail server and Clam AntiVirus are linked using clamav-milter.
1 |
# dnf -y install clamav-milter clamav-milter-systemd |
➁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 |
# vi /etc/mail/clamav-milter.conf Line 6 # Comment or remove the line below. #Example ← Add # at the beginning of the line and comment out Per Line 22-23: Add # Default: no default #MilterSocket /run/clamav-milter/clamav-milter.socket #MilterSocket inet:7357 MilterSocket /var/run/clamav-milter/clamav-milter.socket ← Specify the UNIX socket name for clamav-milter MilterSocketMode 660 ← Specify UNIX socket access rights for clamav-milter Per Linr 96 : Add # Default: no default #ClamdSocket tcp:scanner.mydomain:7357 ClamdSocket unix:/var/run/clamd.scan/clamd.sock ← Specify the UNIX socket name for Clam AntiVirus (match the LocalSocket option in /etc/clamd.d/scan.conf)) Per Line169 : Add # Action to be performed on infected messages # Default: Quarantine #OnInfected Quarantine OnInfected Blackhole ← Destroy virus-infected e-mails. Per Line 191 : 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 252 : Add # Default: LOG_LOCAL6 #LogFacility LOG_MAIL LogFacility LOG_MAIL ← Log output destination to mail log |
➂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 |
# vi /etc/postfix/main.cf Add the following milter_default_action = tempfail smtpd_milters = unix:/var/run/clamav-milter/clamav-milter.socket non_smtpd_milters = unix:/var/run/clamav-milter/clamav-milter.socket |
⑤Add postfix user to clamilt group
1 |
# usermod -G clamilt -a postfix |
⑥Postfix Settings Reflected
1 |
# systemctl restart postfix |
⑦Check with Thunderbird
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.0.5 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・spamass-milter Install
1 |
# dnf -y install spamassassin spamass-milter-postfix |
➁SpamAssassin start
1 |
# systemctl start spamassassin |
➂SpamAssassin Settings
1 2 3 4 |
# vi /etc/mail/spamassassin/v310.pre Per Line 24 : Remove # at the beginning of the line loadplugin Mail::SpamAssassin::Plugin::DCC |
④SpamAssassin configuration file modernization script
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 /var/www/system # vi spamassassin-update.sh #!/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 if [ -f /etc/rc.d/init.d/spamassassin ]; then /etc/rc.d/init.d/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 /var/www/system/spamassassin-update.sh # /var/www/system/spamassassin-update.sh |
Confirm that the SpamAssassin configuration file (local.cf) has been created in the /etc/mail/spamassassin directory with the date of the day
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# ls -l /etc/mail/spamassassin total 1632 drwxr-xr-x 2 root root 40 Apr 27 11:03 channel.d -rw-r--r-- 1 root root 1649 Jan 27 09:00 init.pre -rw-r--r-- 1 root root 500636 Apr 27 11:05 local.cf drwx------ 2 root root 6 Jan 27 09:00 sa-update-keys -rw-r--r-- 1 root root 62 Jan 27 09:00 spamassassin-default.rc -rwxr-xr-x 1 root root 39 Jan 27 09:00 spamassassin-helper.sh -rw-r--r-- 1 root root 55 Jan 27 09:00 spamassassin-spamc.rc -rw-r--r-- 1 root root 500588 Apr 30 2023 user_prefs -rw-r--r-- 1 root root 500588 Apr 27 11:05 user_prefs.org -rw-r--r-- 1 root root 2262 Apr 27 11:04 v310.pre -rw-r--r-- 1 root root 1168 Jan 27 09:00 v312.pre -rw-r--r-- 1 root root 2416 Jan 27 09:00 v320.pre -rw-r--r-- 1 root root 1237 Jan 27 09:00 v330.pre -rw-r--r-- 1 root root 1020 Jan 27 09:00 v340.pre -rw-r--r-- 1 root root 1315 Jan 27 09:00 v341.pre -rw-r--r-- 1 root root 1475 Jan 27 09:00 v342.pre -rw-r--r-- 1 root root 1266 Jan 27 09:00 v343.pre -rw-r--r-- 1 root root 1482 Jan 27 09:00 v400.pre |
Set up cron to automatically run a script daily that updates the SpamAssassin configuration file
1 2 |
# crontab -e 0 2 * * * /var/www/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 |
# vi /etc/postfix/main.cf Add the following milter_default_action = tempfail smtpd_milters = unix:/var/run/clamav-milter/clamav-milter.socket,unix:/run/spamass-milter/postfix/sock ※既にclamav-milterが定義されている場合 non_smtpd_milters = unix:/var/run/clamav-milter/clamav-milter.socket,unix:/run/spamass-milter/postfix/sock ※既にclamav-milterが定義されている場合 |
⑦Restart postfix
1 |
# systemctl restart postfix |
⑧Procmail Settings
Create procmail configuration file
1 2 3 4 5 6 7 8 9 10 |
# vi /etc/procmailrc SHELL=/bin/bash PATH=/usr/bin:/bin DROPPRIVS=yes MAILDIR=$HOME/Maildir DEFAULT=$MAILDIR/ # Log output destination LOGFILE=$HOME/.procmail.log # Detailed log output VERBOSE=ON |
Create procmail log rotation configuration file
1 2 3 4 5 6 |
# vi /etc/logrotate.d/procmail /home/*/.procmail.log { missingok nocreate notifempty } |
⑨Postfix and Procmail integration settings
1 2 3 4 5 6 |
# vi /etc/postfix/main.cf Per Line 478 : add #mailbox_command = /some/where/procmail #mailbox_command = /some/where/procmail -a "$EXTENSION" mailbox_command = /usr/bin/procmail |
Postfix Settings Reflected
1 |
# systemctl restart postfix |
2.2 Spam mail sorting 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 |
# vi spamfolder-create #!/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 against 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 mail sorting
Emails identified as spam by SpamAssassin are delivered to a spam-only mailbox.
1 2 3 4 5 6 |
# vi /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確認
When you send a blank email to yourself, the following message is appended to the header of the received email
X-Spam-Status: No, score=2.3 required=13.0 tests=ALL_TRUSTED,
CONTENT_TYPE_PRESENT,EMPTY_MESSAGE autolearn=no autolearn_force=no
version=4.0.0
X-Spam-Level: **
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 "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X" and make sure the email is not delivered and is sorted into the Spam folder