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

Ubuntu Server26.04 : Tripwire , Logwatch,disk usage check script,DNS Update

Tripwire

Implement a system to detect file tampering on Linux servers by crackers.
This time, Tripwire, a host-based IDS (IDS=Intrusion Detection System), will be installed as the file tampering detection system.
Tripwire detects file additions/changes/deletions by creating a database of file status at the time of installation and comparing the database with the current status of the file.

1 Install

Tripwire requires a site passphrase to secure the "tw.cfg" Tripwire configuration file and the "tw.pol" Tripwire policy file.
Encrypt both files using the specified passphrase. A site passphrase is also required for a single instance of Tripwire.
During the installation process, you will be prompted to enter the "site key passphrase" and the "local key passphrase".

Creating a Site Key Passphrase

Creating a Local Key Passphrase
A local passphrase is required to protect the Tripwire database and report files. The local key used by Tripwire to prevent unauthorized changes to the Tripwire baseline database.

The installation is progressing and will complete.

2. Configuration File Settings

twcfg.txt Edit

Create a configuration file (encrypted signature version)

③ Optimize Policy
Use the following policy optimization scripts to optimize your policy

Policy Optimization Script Contents

Policy File Optimization

Create a policy file (encrypted and signed version) based on the optimized policy file.

Exclude the Tripwire database itself from being checked

Database Creation

3. Functionality Verification

Create test file

Check Tripwire operation

If successful, the following display appears

Delete the test file.

4. Tripwire Autorun

Create a script (tripwire.sh) for reporting results via email and set it to run automatically.

Give execute permission and execute periodically by Cron.

Execute the following and verify that the results are delivered to the specified email address.

Logwatch

Logwatch aggregates various logs and sends them as a daily report via email. It's a useful tool for detecting unauthorized access and issues, as well as monitoring servers.

①Install

Copy the default configuration file

Change email address, etc.

Creating Directories

⑤operation check
When logwatch is installed, cron is registered by default, so you will receive daily report emails.
If you want to check it immediately, do the following

Disk Usage Check Script

1. Script creation

Contents of disk_capacity_check.sh

2. Execution Confirmation

Check the current usage rate

It will be displayed as follows:

Create dummy files to achieve a usage rate of 80% or higher (in this example, a file named dummyfile approximately 4GB in size).

③Confirm again

Verify that it is running and has reached over 80%.

Run the disk capacity check script

An email with the subject line "Disk usage alert: 92%" will be sent to the specified email address.

Delete the created "dummyfile"

Scheduled Execution Settings

DNS Update

Whenever the internet connection is lost or the router reboots, causing the global IP address to change, you must access the dynamic DNS service to notify it of the new IP address.

Create a dedicated Python file and schedule it for regular execution via Cron.
This time, it's about DNS settings in Valudomain.

Content of ddnsset.py

IP Address Log File Creation

Run periodically

Copied title and URL