業務用エアコン関連の技術情報、エラーコード、環境問題対策に関する別サイト「エアコンの安全な修理・適切なフロン回収」

Ubuntu Server25.10 : Anti-Virus(Clamav) , Mail Server

1.Anti-virus software Clamav installed

1.1 Install

The clamav-related configuration files are installed in the "/etc/clamav/" folder.

1.2 Virus definition updates

Change configuration file

1.3 Virus Check Confirmation

①Running manual virus checks

Infected files: 0, so no virus

②Download a test virus to detect viruses
Download a trial harmless virus to test detection

The virus is notified with the message "FOUND" and "Infected files: 1". Also, since the "--remove" option is attached, the test virus has been removed.

1.4 Create a script file to do a full scan

Contents of clam-full.sh (new)

②grant execution authority

③Create a folder for virus quarantine (if it already exists, it is OK, but if it does not, a runtime error will occur because it is specified as an excluded directory in the above script).

④try and run it.

⑤Scheduled virus scan execution with cron

2. Mail Server

2.1 Postfix : Installation/Configuration

Install Postfix and build an SMTP server. 25/TCP is used for SMTP.
To prevent unauthorized mail relay, use the SASL function of Dovecot (see below), and configure Postfix so that authentication is required even for outgoing mail.

①Install

Installation Status Screen
You will be asked to select a general configuration setting, select "No Configuration" to set it manually later.

②Configuration File Edit

[main.cf] Edits

Line 82:Uncomments
mail_owner = postfix

Line 108:Add hostname specification
myhostname = mail.[domain name]

Line 115:Domain Name Specification Addition
mydomain = [domain name]

Line 133 : Comments
#myorigin = /etc/mailname

Line 135:Uncomments
myorigin = $mydomain

Line 149:Uncomments
inet_interfaces = all

Line 197:Uncomments
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

Line 240:Uncomments
local_recipient_maps = unix:passwd.byname $alias_maps

Line 285:Uncomments
mynetworks_style = subnet

Line 302:Self-Network Addendum
mynetworks = 127.0.0.0/8, 192.168.11.0/24

Line 423:Uncomments
alias_maps = hash:/etc/aliases

Line 434:Uncomments
alias_database = hash:/etc/aliases

Line 456:Uncomments
home_mailbox = Maildir/

Line 592:Add a comment and append it below
#smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_banner = $myhostname ESMTP

Line 666:Add
sendmail_path = /usr/sbin/postfix

Line 670:Uncomments
newaliases_path = /usr/bin/newaliases

Line 675:Uncomments
mailq_path = /usr/bin/mailq

Line 681:Uncomments
setgid_group = postdrop

#Add to the last line:
#Limit sent and received email size to 10MB
message_size_limit = 10485760
#Limit mailbox size to 1GB
mailbox_size_limit = 1073741824
#SMTP Authentication 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

③master.cf edit

[master.cf] Edits

Line 19,23 : Uncomments
submission inet n - y - - smtpd
# -o syslog_name=postfix/submission
# -o smtpd_forbid_unauth_pipelining=no
# -o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
# -o smtpd_tls_auth_only=yes

④Reflecting settings

2.2 Dovecot : Installation/Configuration

Install Dovecot and build a POP/IMAP server, using 110/TCP for POP and 143/TCP for IMAP

①Configure Dovecot to provide SASL functionality for Postfix

②Configuration Reflection

2.3 Port Open

2.4 Email User Account Registration

Register a user account for e-mail.
This setting is for when a user account on the OS is also used for e-mail.
If you want to use mail with a user account on the OS, you do not need to make any additional settings, only register an OS user.

①Mail Client Install

②Mailboxes are set to refer to Maildir

2.5 operation check ①

①Test sending mail
Send test mail to yourself [mail (user name)@(host name)].(This time, general user huong)

Ctrl + D key to exit the main text

➁Check incoming mail

2.6 operation check ②

Set up and confirm your account in Mozilla Thunderbird. This time we will set it up with the general user "huong".
①Start Thunderbird and click [New Account][Email] in the [Three] Button-menu in the upper right corner.

Full name : Any name
Email address : huong@<domain-name>
「Continue」click

[EDIT CONFIGURATION] click

Incoming server settings
Set [Connection security] to [None] and click [Continue].

Sending Server Settings
Set [Connection security] to [None] and click [Test].

[Continue] click

Enter the user's password in the “Password” field and click "Continue"

[Continue] click

Click “Finish” when the email account has been successfully created.

2.7 Applying ClamAV to the Postfix mail server

Configure Postfix and ClamAV to enable real-time scanning of incoming and outgoing emails.

①Install Amavisd and Clamav Daemon, then start Clamav Daemon.

If the server does not use a fully qualified domain name (FQDN) as its hostname, Amavis may fail to start.
Additionally, since the hostname of the operating system may change, set a valid hostname directly in the Amavis configuration file.

②Editing 15-content_filter_mode

③Register your own domain name

④Main.cf Editing

⑤Editing master.cf

⑥Postfix Settings Reflected

⑦If you send an email to yourself using Thunderbird or similar software, you'll know it worked if the following message appears in the header of the received email.

X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
Return-Path: xxxxx@xxxxxxx.com
X-Original-To: xxxxx@xxxxxxx.com
Delivered-To: xxxxx@xxxxxxx.com
Received: from localhost (localhost [127.0.0.1])
  by mail.xxxxxxx.com (Postfix) with ESMTP id 88BD160EF5
  for xxxxx@xxxxxxx.com; Sun, 11 Jan 2026 10:04:39 +0900 (JST)
X-Virus-Scanned: Debian amavis at xxxxxxx.com
Received: from mail.xxxxxxx.com ([127.0.0.1])
 by localhost (mail.xxxxxxx.com [127.0.0.1]) (amavis, port 10024) with ESMTP
 id vpD7gdZWgTMP for xxxxx@xxxxxxx.com;

 Sun, 11 Jan 2026 10:04:39 +0900 (JST)
Received: from [192.168.11.8] (xxxxxxx.setup [192.168.11.1])
  by mail.xxxxxxx.com (Postfix) with ESMTPA id 732CA60EF4
  for xxxxx@xxxxxxx.com; Sun, 11 Jan 2026 10:04:39 +0900 (JST)
Message-ID: 39ea6861-71c6-429e-b84e-0435eea70093@xxxxxxx.com
Date: Mon, 21 Apr 2025 06:49:39 +0900
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
From: xxxxx xxxxx@xxxxxxx.com
Content-Language: en-US
To: xxxxx xxxxx@xxxxxxx.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

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.8 Applying SpamAssassin to the Postfix mail server

2.5.1 spamassassin

①Install

②SpamAssassin Configuration

SpamAssassin Configuration File Update Script

[spamassassin-update.sh] 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

if [ -f /etc/init.d/spamd ]; then
/etc/init.d/spamd restart > /dev/null
else
systemctl restart spamd > /dev/null
fi
fi
cp user_prefs user_prefs.org

Grant the spamassassin-update script execution permissions and run it.

Confirm that the SpamAssassin configuration file (local.cf) has been created in the /etc/mail/spamassassin directory with the date of the day
Install unzip beforehand

Set up cron to automatically run a script daily that updates the SpamAssassin configuration file

④spamass-milter startup and automatic startup settings

  • Create a directory named ".Spam" in Maildir format for storing spam emails
  • Creation must be performed by the target user.

2.5.2 Preparing Procmail

①Procmail Install

If installed, the following result will be returned.

②Procmail Settings
Entering settings in /etc/procmailrc, which governs all mail filters, applies them to all users.
Entering settings in /home/[user]/.procmailrc, which is each user's individual mail filter file, applies the filter only to that user.
This time, we will enter settings in /etc/procmailrc to apply them to all users.

procmailrc contents (new creation)

#Set the path
PATH=/bin:/usr/bin:/usr/local/bin
#Mailbox Settings
MAILDIR=$HOME/Maildir
DEFAULT=$MAILDIR/
#Specify the output location for Procmail log files
LOGFILE=$MAILDIR/procmaillog
#Specify the path to the lock file
LOCKFILE=$HOME/.lockmail
#If the mail header does not contain an "X-Spam-***" entry, SpamAssassin will be launched.
:0fw
*!^X-Spam.*
|spamassassin
#If the email header contains "X-Spam-Status: Yes", the email will be stored in the ".Spam" directory.
:0
*^X-Spam-Status: Yes
$MAILDIR/.Spam/

2.5.3 Postfix Configuration

① Editing main.cf

②Reflecting Settings and Launching

2.5.4 Learning about spam emails

Teach the system to recognize all contents within every user's ".Spam" directory as spam email.
①Learning about spam emails

②Learning regular emails

③Create a script and register it with Cron
Name the file something like "spam-learns.sh" and place it under /opt/scripts.
After saving the script, grant it executable permissions using chmod 750 spam-learns.sh.

[spam-learns.sh] Contents

#! /bin/sh
#Learning about spam emails
/usr/bin/sa-learn --spam /home/*/Maildir/.Spam/cur
#Learning regular emails
/usr/bin/sa-learn --ham /home/*/Maildir/cur

#If you want to force the deletion of the contents of the spam email storage directory, add the following line:
/bin/rm -f /home/*/Maildir/.Spam/cur

Once spam-learns.sh is created, create the definition file directly under /lib/systemd/system.
Name it so that it ends with .service, like spam-learns.service.
Define the Type as simple.

[spam-learns.service] Content
[Unit]
Description=demo sample node.js program

[Service]
Type=simple
ExecStart= /opt/script/spam-learns.sh
Restart=always

[Install]
WantedBy=multi-user.target

④If you send an empty email to yourself using Thunderbird or similar software and see a message like the following in the received email header, it means the process was successful.

X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
Return-Path: xxxxx@xxxxxxx.com
X-Spam-Checker-Version: SpamAssassin 4.0.2-rc2 (2025-08-11) on Lepard
X-Spam-Level: **
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.2-rc2
X-Original-To: xxxxx@xxxxxxx.com
Delivered-To: xxxxx@xxxxxxx.com
Received: from localhost (localhost [127.0.0.1])
  by mail.xxxxxxx.com (Postfix) with ESMTP id B35F3416EE
  for xxxxx@xxxxxxx.com; Sun, 11 Jan 2026 10:29:51 +0900 (JST)
X-Virus-Scanned: Debian amavis at xxxxxxx.com
Received: from mail.xxxxxxx.com ([127.0.0.1])
 by localhost (mail.xxxxxxx.com [127.0.0.1]) (amavis, port 10024) with ESMTP
 id mkU1ZPnLVwqK for xxxxx@xxxxxxx.com;
Sun, 11 Jan 2026 10:29:51 +0900 (JST)
Received: from [192.168.11.6] (buffalo.setup [192.168.11.1])
  by mail.xxxxxxx.com (Postfix) with ESMTPA id 9A9A8416E9
  for xxxxx@xxxxxxx.com; Sun, 11 Jan 2026 10:29:51 +0900 (JST)
Message-ID: a9f5dc53-7a3a-4ea1-ba34-92cc76bf13b4@xxxxxxx.com
Date: Sun, 11 Jan 2026 10:29:52 +0900
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
From: xxxxx xxxxx@xxxxxxx.com
Content-Language: en-US
To: xxxxx xxxxx@xxxxxxx.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Subject:

⑤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
The header states
Check the emails under /home/[user]/Maildir/.Spam/new/

Return-Path: <xxxxx@xxxxxxx.com>
X-Spam-Checker-Version: SpamAssassin 4.0.2-rc2 (2025-08-11) on Lepard
X-Spam-Flag: YES
X-Spam-Level:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X-Spam-Status: Yes, score=1001.8 required=13.0 tests=ALL_TRUSTED,
     CONTENT_TYPE_PRESENT,GTUBE,HTML_MESSAGE,MPART_ALT_DIFF,
     MULTIPART_ALTERNATIVE autolearn=no autolearn_force=no

     version=4.0.1
X-Spam-Report:
     * 0.1 ALL_TRUSTED Passed through trusted hosts only via SMTP
     * 1000 GTUBE BODY: Generic Test for Unsolicited Bulk Email
     * -0.1 CONTENT_TYPE_PRESENT exists:Content-Type
     * 0.1 MULTIPART_ALTERNATIVE Multipart/alternative
     * 0.7 MPART_ALT_DIFF BODY: HTML and text parts are different
     * 1.0 HTML_MESSAGE BODY: HTML included in message

Copied title and URL