Debian12.8 ; Anti-virus(Clamav) 、Mail Server

1. Antivirus software Clamav installed

Install Clam AntiVirus, a free anti-virus software for Linux, as an anti-virus measure.
By installing this anti-virus software, you can not only scan the entire server for viruses, but also scan incoming and outgoing mail for viruses if you build and configure a mail server.

1.1 Install

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

1.2 Virus Definition Update

Edit configuration file

Automatic virus definition update confirmation
Ensure that the service is registered for automatic virus definition updates.

It appears as follows

Logs are recorded in the file /var/log/clamav/freshclam.log.

1.3 Virus Check Confirmation

①Running manual virus checks

Infected files: 0, so no virus

②Virus detection by downloading test viruses
Download a harmless virus and test it for detection.

As you can see, it notifies me of the virus by displaying “FOUND” and “Removed.” and “Infected files: 1”. The “--remove” option was added, so the test virus was removed.

①Create a script file storage directory (/opt/script) in advance.

②Create script file

Contents of clam-full.sh (new)

③execute authorization

④Create a folder for virus quarantine
If not, a runtime error will occur because the above script specifies it as an excluded directory.

⑤Script Execution

akes quite a long time to complete.
Logs are recorded in the /var/log/clamav/clamscan.log file.

⑤Scheduled virus scan execution with cron

In the above example, it runs regularly every Monday at 2:00 AM.

2. Mail server installation

Postfix was developed as a Mail Transport Agent (MTA) to replace sendmail, and is a mail server that is highly compatible with sendmail, secure, easy to maintain, and fast.
In addition, since Postfix only functions as an SMTP server for sending mail, the POP server Dovecot for receiving mail will be installed separately in the latter half.

2.1 Postfix : Installation Configuration

Install Postfix
Install Postfix and build an SMTP server; SMTP uses 25/TCP.
To prevent unauthorized mail relay, use the SASL function of Dovecot, described below, and configure Postfix so that authentication is also required for sending.

You will be asked to select general configuration settings, select "No configuration " to set them manually later

Edit configuration file (main.cf)

editorial content

Edit configuration file (master.cf)

Editorial content

Reflect settings, reboot

2.2 Dovecot : Installation Configuration

Install Dovecot
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

Reflect settings, reboot

2.3 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, no additional configuration is required, just register the OS user

Mail client installed

Mailboxes are set to refer to Maildir

2.4 Opening Ports

2.5 operation check ①

①Send test mail to yourself [mail (user name)@(host name)].
user name : 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

①Start Thunderbird, and click "Tools", "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
Click on "Configure manually"

④Set "INCOMMING SERVER" and "OUTGOING SERVER" as shown below and click "Re-test".

⑤The "Server Found" message appears.(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.

3 Applied ClamAV to mail server Postfix

Set up Postfix and Clamav to work together to scan incoming and outgoing mail in real time.

Install Amavisd and Clamav Daemon and start Clamav Daemon

If the server is not using a fully qualified domain name (FQDN) as the hostname, Amavis may fail to start. Also, since the OS hostname may change, set a valid hostname directly in the Amavis configuration file

Virus Scan Enable

Register your own domain name

Edit configuration file (Main.cf)

Edit configuration file (master.cf)

Editorial content

Settings reflect

When you send an e-mail to yourself on Thuderbird, etc., it is successful if you see the following message in the header of the incoming e-mail.

X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
Return-Path: xxxxxx@korodes.com
X-Original-To: xxxxxx@korodes.com
Delivered-To: xxxxxx@korodes.com
Received: from localhost (localhost [127.0.0.1])
by mail.korodes.com (Postfix) with ESMTP id 8616FBFE40
for xxxxxx@korodes.com; Mon, 18 Nov 2024 11:27:19 +0900 (JST)
X-Virus-Scanned: Debian amavis at korodes.com
Received: from mail.korodes.com ([127.0.0.1])
by localhost (mail.korodes.com [127.0.0.1]) (amavis, port 10024) with ESMTP
id sDS_Efu-GlbO for xxxxxx@korodes.com;

Mon, 18 Nov 2024 11:27:19 +0900 (JST)
Received: from [192.168.11.45] (buffalo.setup [192.168.11.1])
by mail.korodes.com (Postfix) with ESMTPA id 5E712BFE3D
for xxxxxx@korodes.com; Mon, 18 Nov 2024 11:27:19 +0900 (JST)
Message-ID: 7001ca3e-176d-4edd-b798-33e310679ea0@korodes.com
Date: Mon, 18 Nov 2024 11:27:17 +0900
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
From: huong xxxxxx@korodes.com
Content-Language: en-US
To: xxxxxx@korodes.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

4 Apply spam checks to the mail server

4.1 Spam checking using spamassassin and procmail

spamassassin and procmail installation

Configure procmail
If you want to apply the settings to all users
Create /etc/procmailrc
To configure for each individual, create a ~/.procmailrc in each user's home directory.
Create /etc/procmailrc this time

Contents of procmailrc

Create a .Spam directory in each user's ~/Maildir directory

Edit postfix configuration file
Do it as root user

Restart postfix and spamassassin

Confirmed by Thudrtbird
If you send an e-mail to yourself and the header displays the following, it is normal.

X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
Return-Path: huong@korodes.com
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on Lepard
X-Spam-Level: ***
X-Spam-Status: No, score=3.1 required=5.0 tests=ALL_TRUSTED,EMPTY_MESSAGE,
MISSING_SUBJECT autolearn=no autolearn_force=no version=4.0.0

X-Original-To: xxxxxx@korodes.com
Delivered-To: xxxxxx@korodes.com
Received: from localhost (localhost [127.0.0.1])
by mail.korodes.com (Postfix) with ESMTP id 3FCCFBFE42
for xxxxxx@korodes.com; Mon, 18 Nov 2024 11:40:47 +0900 (JST)
X-Virus-Scanned: Debian amavis at korodes.com
Received: from mail.korodes.com ([127.0.0.1])
by localhost (mail.korodes.com [127.0.0.1]) (amavis, port 10024) with ESMTP
id TfT3LkYTvvVm for xxxxxx@korodes.com;
Mon, 18 Nov 2024 11:40:46 +0900 (JST)
Received: from [192.168.11.45] (buffalo.setup [192.168.11.1])
by mail.korodes.com (Postfix) with ESMTPA id A0E46BFE41
for xxxxxx@korodes.com; Mon, 18 Nov 2024 11:40:46 +0900 (JST)
Message-ID: e46b3fab-c151-4425-b1a6-b83b6d6e204c@korodes.com
Date: Mon, 18 Nov 2024 11:40:46 +0900
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
From: huong xxxxxx@korodes.com
Content-Language: en-US
To: xxxxxx@korodes.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

4.2 Spam Email Learning

SpamAssassin's email learning functionality improves the accuracy of its judgments

Learns all contents of ".Spam" directory as spam mail

Learning of non-spam mail (normal mail)

Creating scripts for automatic learning

SpamAssassin automatically starts at system startup

Copied title and URL