Contents
clamav ( アンチウィルスソフト )のインストール
1.Clam AntiVirusインストール
# vi /etc/clamd.d/scan.conf
●14行目
# Default: disabled
LogFile /var/log/clamd.scan ← コメント解除
●77行目
# Default: disabled
PidFile /run/clamd.scan/clamd.pid ← コメント解除
●96行目
# 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 ← コメント解除
●219行目
# Run as another user (clamd must be started by root for this option to work)
# Default: don’t drop privileges
#User clamscan ← 行頭に#を追加してコメントアウト(root権限で動作するようにする)
3.ウイルス定義ファイル更新設定
●75行目
「DatabaseMirror database.clamav.net」の行頭に「#」を挿入し、
「DatabaseMirror db.jp.clamav.net」を追加
#DatabaseMirror database.clamav.net
DatabaseMirror db.jp.clamav.net
●151 行目あたり
「NotifyClamd /etc/clamd.d/scan.conf」を追加
#NotifyClamd /path/to/clamd.conf
NotifyClamd /etc/clamd.d/scan.conf
daily.cvd database is up-to-date (version: 26535, sigs: 1983975, f-level: 90, builder: raynman)
main.cvd database is up-to-date (version: 62, sigs: 6647427, f-level: 90, builder: sigmgr)
bytecode.cvd database is up-to-date (version: 333, sigs: 92, f-level: 63, builder: awillia2)
# vi /etc/clamd.d/scan.conf
●14行目
# Default: disabled
LogFile /var/log/clamd.scan ← コメント解除
●77行目
# Default: disabled
PidFile /run/clamd.scan/clamd.pid ← コメント解除
●96行目
# 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 ← コメント解除
●219行目
# Run as another user (clamd must be started by root for this option to work)
# Default: don’t drop privileges
#User clamscan ← 行頭に#を追加してコメントアウト(root権限で動作するようにする)
5.Clam AntiVirus起動
# systemctl enable clamd@scan ← clamd自動起動設定
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 ← 動作確認
● clamd@scan.service – clamd scanner (scan) daemon
Loaded: loaded (/usr/lib/systemd/system/clamd@.service; enabled; vendor pr>
Active: active (running) since Mon 2022-05-09 16:00:43 JST; 31s ago
Docs: man:clamd(8)
man:clamd.conf(5)
https://www.clamav.net/documents/
Main PID: 2774 (clamd)
Tasks: 2 (limit: 4292)
Memory: 1.1G
CPU: 18.531s
CGroup: /system.slice/system-clamd.slice/clamd@scan.service
mq2774 /usr/sbin/clamd -c /etc/clamd.d/scan.conf5月 09 16:00:43 fedora clamd[2774]: ELF support enabled.
5月 09 16:00:43 fedora clamd[2774]: Mail files support enabled.
5月 09 16:00:43 fedora clamd[2774]: OLE2 support enabled.
■テスト用ウィルスをダウンロードして、ウィスルスキャンを実施
# clamscan –infected –remove –recursive
/root/eicar.com: Win.Test.EICAR_HDB-1 FOUND ← ウィルス検知
/root/eicar.com: Removed. ← ウィルス削除
———– SCAN SUMMARY ———–
Known viruses: 8616037
Engine version: 0.103.5
Scanned directories: 1
Scanned files: 10
Infected files: 1
Data scanned: 0.02 MB
Data read: 0.01 MB (ratio 2.00:1)
Time: 27.879 sec (0 m 27 s)
Start Date: 2022:05:09 16:02:51
End Date: 2022:05:09 16:03:19
# cd /var/www/system
clamscan.sh を次の内容で/var/www/systemに作成
# vi /var/www/system/clamscan.sh
#!/bin/bash
PATH=/usr/bin:/bin
# excludeopt setup
excludelist=/var/www/system/clamscan.excludeif [ -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} /
8.ウイルススキャン除外ディレクトリー設定
# echo “/sys/” >> /var/www/system/clamscan.exclude
# echo “/proc/” >> /var/www/system/clamscan.exclude
sys ディレクトリ、proc ディレクトリは対象外にする
no crontab for root – using an empty one
Fedoraには初期状態ではcronがありませんので、下記を実行してインストールしてください
# dnf install cronie cronie-anacron
再度
# crontab -e
0 1 * * * /var/www/system/clamscan.sh > /dev/null 2>&1
メールサーバー インストール
1. Postfixのインストール
1.1 インストール
Postfix をインストールして SMTP サーバーを構築します
postfix-3.6.4-1.fc35.x86_64
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
# systemctl is-enabled postfix.service
enabled
# cp -p /etc/postfix/master.cf `date ‘+/etc/postfix/master.cf.%Y%m%d’`
メール不正中継防止のため、Dovecot の SASL 機能を利用して、送信にも認証を要求するように Postfix を設定します
●96 行目あたりに追加
#myhostname = virtual.domain.tld
myhostname = mail.<ドメイン>
●103 行目あたりに自ドメイン名を追加
#mydomain = domain.tld
mydomain = <ドメイン>
●118 行目あたりコメントアウト削除
myorigin = $mydomain
●135 行目あたり変更
inet_interfaces = all
●183 行目あたりに追加
183 行目あたりをコメントアウトし、184 行目に追加します。
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
●287 行目あたりに追加
#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は各自環境に合わす
●440 行目あたりコメントア削除削除
メールの格納形式の設定をします。
#home_mailbox = Mailbox
home_mailbox = Maildir/
●447 行目あたりに追加
#mail_spool_directory = /var/mail
mail_spool_directory = /var/spool/mail
●593 行目あたりに追加
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_banner = $myhostname ESMTP unknown
●以下の内容を最終行に追加
# 送受信メールサイズを 10M に制限
message_size_limit = 10485760
# メールボックスサイズを 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
SMTP ポート(25 番ポート) の解放
success
# firewall-cmd –reload
success
2.Dovecotインストール
# vi /etc/dovecot/dovecot.conf
●25 行目あたりに追加
# protocols = imap pop3 lmtp
protocols = imap pop3
●30行目 : コメント解除
# IPv4 のみリスンする場合は [::] を削除
listen = *, ::
2.3 10-auth.conf ファイルを編集
●10行目 : コメント解除し変更
プレーンテキスト認証も許可する場合
disable_plaintext_auth = no
●100行目 : 追記
auth_mechanisms = plain login
●31行目 : 追記
mail_location = maildir:~/Maildir
●107-109行目 : コメント解除して追記
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
●8 行目あたり
「ssl = required」を「ssl = yes」に変更
ssl = yes
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
# firewall-cmd –permanent –add-service=imap
# firewall-cmd –reload
3.メールユーザー作成と動作確認
3.1 事前準備
①新規ユーザーの為の前処理
新規でユーザーを追加した場合、自動的にメールの送受信ができるよう設定をします。
# chmod -R 700 /etc/skel/Maildir/
# echo “~/Maildir/”> /etc/skel/.forward
# chmod 600 /etc/skel/.forward
②既存ユーザーのメール環境前処理
すでに作成してあるユーザーがメールの送受信が出来るよう設定をします。
# mkdir -p /home/huongMaildir/{new,cur,tmp}
# chown -R huong:huong /home/huong/Maildir/
# chmod 700 /home/huong/Maildir
# chmod 700 /home/huong/Maildir/{new,cur,tmp}
3.2 ユーザーアカウント作成
メールクライアントインストール
# dnf -y install mailx
ユーザー [linux] を追加
# useradd linux
# passwd linux
ユーザー linux のパスワードを変更。
新しい パスワード:
新しい パスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。
①メールユーザーでログインして、テストメールを送る
$ mail linux@localhost
Subject: Test Mail
mail test
. ← 本文終了するには「.」を入力
EOT
Heirloom Mail version 12.5 7/5/10. Type ? for help.
“/home/linux/Maildir”: 1 message 1 new
>N 1 linux@korodes.com Wed May 11 13:05 17/506 “Test Mail”
& 1
Message 1:
From linux@korodes.com Wed May 11 13:05:10 2022
Return-Path: <linux@korodes.com>
X-Original-To: linux@localhost
Delivered-To: linux@localhost
Date: Wed, 11 May 2022 13:05:10 +0900
To: linux@localhost
Subject: test
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: linux@korodes.com
Status: Rmail test& q
Held 1 message in /home/linux/Maildir
Mozilla Thunderbirdにアカウントを設定し、確認します
①Thunderbirdを起動し、「ツール」「アカウント設定」


「メールアドレス」は先ほど追加した「linux@korodes.com」
「パスワード」はlinux@korodes.comのパスワード
をそれぞれ入力し、「手動設定」クリック






Mail サーバー : Postfix + Clamav + Amavisd+SpamAssassin
1.メールのリアルタイムスキャン
●77行目:変更
PidFile /var/run/clamd.scan/clamd.pid
●81行目:コメント解除
TemporaryDirectory /var/tmp
●96行目:変更
LocalSocket /var/run/clamd.scan/clamd.sock
# chown clamscan. /var/log/clamd.scan
# systemctl enable clamd@scan
# vi /etc/amavisd/amavisd.conf
●13 行目あたり行頭の#削除
@bypass_spam_checks_maps = (1); # controls running of anti-spam code
● 23行目:自ドメイン名に変更
$mydomain = ‘ドメイン名’;
●28 行目あたりコメントアウト
#$QUARANTINEDIR = undef; # -Q
●125 行目あたりコメントアウト
# $virus_admin = undef; # notifications recip
●158行目:コメント解除して自ホスト名に変更
$myhostname = ‘mail.ドメイン名‘;
# systemctl enable amavisd
Created symlink /etc/systemd/system/multi-user.target.wants/amavisd.service → /usr/lib/systemd/system/amavisd.service.
④Postfix の設定
# 最終行に追記
content_filter=smtp-amavis:[127.0.0.1]:10024
# vi /etc/postfix/master.cf
# 最終行に追記
smtp-amavis unix – – n – 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n – n – – smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
「X-Virus-Scanned: amavisd-new at korodes.」が表示される

2.メールのスパム対策
# systemctl start spamassassin
# systemctl enable spamassassin
Created symlink /etc/systemd/system/multi-user.target.wants/spamassassin.service → /usr/lib/systemd/system/spamassassin.service.
●24 行目あたり行頭の#を削除
loadplugin Mail::SpamAssassin::Plugin::DCC
# vi /var/www/system/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 ] && exitunzip main.zip >/dev/null 2>&1
[ $? -ne 0 ] && exit
rm -f main.zipmv 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
# SpamAssassin再起動
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
spamassassin-update スクリプトに実行権限を付与し、実行
# /var/www/system/spamassassin-update.sh
作成されていることを確認
合計 176
drwxr-xr-x 2 root root 40 5月 11 18:44 channel.d
-rw-r–r– 1 root root 1194 7月 24 2021 init.pre
-rw-r–r– 1 root root 276 7月 24 2021 local.cf
-rw-r–r– 1 root root 126639 5月 11 20:11 main.zip
drwx—— 2 root root 6 7月 24 2021 sa-update-keys
-rw-r–r– 1 root root 62 7月 24 2021 spamassassin-default.rc
-rwxr-xr-x 1 root root 39 7月 24 2021 spamassassin-helper.sh
-rw-r–r– 1 root root 55 7月 24 2021 spamassassin-spamc.rc
-rw-r–r– 1 root root 2523 5月 11 20:05 v310.pre
-rw-r–r– 1 root root 1194 7月 24 2021 v312.pre
-rw-r–r– 1 root root 2416 7月 24 2021 v320.pre
-rw-r–r– 1 root root 1237 7月 24 2021 v330.pre
-rw-r–r– 1 root root 1020 7月 24 2021 v340.pre
-rw-r–r– 1 root root 1309 7月 24 2021 v341.pre
-rw-r–r– 1 root root 1469 7月 24 2021 v342.pre
-rw-r–r– 1 root root 1264 7月 24 2021 v343.pre
0 2 * * * /var/www/system/spamassassin-update.sh > /dev/null 2>&1
# vi /etc/postfix/master.cf
●12行目あたり
11 行目の行頭に「#」を追加し12 行目にSpamAssassin 設定を追加
# smtp inet n – n – – smtpd
smtp inet n – n – – smtpd
-o content_filter=spamassassin
●最終行へ追加
smtp-amavis unix – – n – 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n – n – – smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
spamassassin unix – n n – – pipe
user=nobody argv=/usr/bin/spamc -e /usr/sbin/sendmail.postfix -oi -f ${sender} ${recipient}
⑤postfix を再起動
