Operating System CentOS

How to Install OSSEC HIDS on AlmaLinux 9 or Rocky Linux 9

Install the OSSEC host intrusion detection system on AlmaLinux 9 or Rocky Linux 9, verify the release signature, and set up e-mail alerts and file integrity monitoring.

OSSEC is a host-based intrusion detection system (HIDS): it analyses logs, checks file integrity, looks for rootkits and can react to attacks by blocking the source. This guide installs OSSEC 4.4.1 from the signed source release as a local installation, meaning it monitors only the server it runs on, on AlmaLinux 9 or Rocky Linux 9. The same steps apply to CentOS Stream 9 and RHEL 9. At the end OSSEC is running, sending e-mail alerts and watching the directories you choose.

CentOS 7 reached end of life in June 2024 and no longer receives security updates; AlmaLinux 9 and Rocky Linux 9 are the usual replacements. OSSEC itself is still maintained. The project is managed by Atomicorp, the current stable release is 4.4.1, and it is distributed both as source and as RPM/DEB packages.

Requirements

  • A server running AlmaLinux 9, Rocky Linux 9, CentOS Stream 9 or RHEL 9.
  • A user with sudo rights (the examples use deploy).
  • An e-mail address for alerts and the SMTP server that accepts mail for it.

Step 1: Install the build dependencies

OSSEC is compiled during installation. Install the compiler and the development libraries the OSSEC documentation lists for the Red Hat family:

sudo dnf install zlib-devel pcre2-devel make gcc sqlite-devel openssl-devel libevent-devel libcurl-devel systemd-devel

On AlmaLinux 9 all of these -devel packages come from the AppStream repository, which is enabled by default. If dnf cannot find one of them on another RHEL 9 compatible system, enable the CRB repository with sudo dnf config-manager --set-enabled crb and run the command again.

Step 2: Download and verify the release

Import the OSSEC release signing key from the project site:

cd ~
curl -O https://www.ossec.net/files/OSSEC-ARCHIVE-KEY.asc
gpg --import OSSEC-ARCHIVE-KEY.asc

Download the 4.4.1 source archive and its detached signature from the project's GitHub repository. The 4.4.1 release page carries only the signature files; the archive they sign is the source archive that GitHub generates for the 4.4.1 tag, so fetch the archive from the tag URL and the signature from the release:

curl -L -o ossec-hids-4.4.1.tar.gz https://github.com/ossec/ossec-hids/archive/4.4.1.tar.gz
curl -LO https://github.com/ossec/ossec-hids/releases/download/4.4.1/ossec-hids-4.4.1.tar.gz.asc

Verify the signature:

gpg --verify ossec-hids-4.4.1.tar.gz.asc ossec-hids-4.4.1.tar.gz

A successful check prints Good signature from "Scott R. Shinn <scott@atomicorp.com>" followed by the primary key fingerprint. A warning that the key is not certified with a trusted signature is expected on a freshly imported key. Compare the fingerprint with the one published in the OSSEC documentation: B50F B194 7A0A E311 45D0 5FAD EE1B 0E6B 2D83 87B7. Do not continue if GnuPG reports a bad signature or a different key; delete both files, download them again and repeat the check. For a later release, replace 4.4.1 in all three commands; if the release page then offers a .tar.gz file next to the .asc file, download that file instead of the tag archive.

Step 3: Run the installer

Unpack the archive and start the installation script as root:

tar -zxf ossec-hids-4.4.1.tar.gz
cd ossec-hids-4.4.1
sudo ./install.sh

The script asks a series of questions and then compiles and installs the software. Reasonable answers for a single server:

QuestionAnswer
LanguagePress Enter for English
Kind of installation (server, agent, local, hybrid)local
Where to installPress Enter for /var/ossec
E-mail notificationy, then your address and SMTP server
Integrity check daemony
Rootkit detection enginey
Active responsey to let OSSEC block attacking addresses, n to only receive alerts

If you enable active response, add your own IP address to the white list when the installer offers it, so that a few mistyped passwords cannot lock you out. If your mail provider requires a login, answer yes to the SMTP authentication question and enter the user name, password and port.

Use server instead of local only when this machine should collect events from OSSEC agents on other hosts. A server listens on UDP port 1514, which must then be opened in the firewall.

Step 4: Start OSSEC

Start the daemons and check that they are running:

sudo /var/ossec/bin/ossec-control start
sudo /var/ossec/bin/ossec-control status

OSSEC ships a systemd unit named ossec-hids.service that wraps ossec-control. Check whether the installer registered it and, if it is listed, enable it so OSSEC starts at boot:

systemctl list-unit-files ossec-hids.service
sudo systemctl enable ossec-hids

Step 5: Adjust the configuration

The main configuration file is /var/ossec/etc/ossec.conf. Open it as root:

sudo vi /var/ossec/etc/ossec.conf

The <global> block holds the mail settings you entered during installation. Change them here if alerts do not arrive:

<global>
  <email_notification>yes</email_notification>
  <email_to>admin@example.com</email_to>
  <smtp_server>mail.example.com</smtp_server>
  <email_from>ossec@example.com</email_from>
</global>

The <syscheck> block controls file integrity monitoring. By default the listed directories are checked on a schedule. To be alerted as soon as a file changes, and to see what changed in text files, add the realtime and report_changes attributes to the directories that matter to you:

<directories realtime="yes" report_changes="yes" check_all="yes">/etc,/usr/bin,/usr/sbin</directories>
<directories realtime="yes" report_changes="yes" check_all="yes">/var/www</directories>

Files that change constantly produce noise. Exclude them with <ignore> lines in the same block, for example <ignore>/etc/mtab</ignore>. Restart OSSEC after every change:

sudo /var/ossec/bin/ossec-control restart

Step 6: Check that alerts are generated

OSSEC writes its own log to /var/ossec/logs/ossec.log and every alert to /var/ossec/logs/alerts/alerts.log. Look for start-up errors first, then watch the alerts:

sudo tail -n 50 /var/ossec/logs/ossec.log
sudo tail -f /var/ossec/logs/alerts/alerts.log

Open a second SSH session and enter a wrong password once; an authentication failure alert should appear within seconds. You should also receive a mail saying that the OSSEC server started. If no mail arrives, check ossec.log for messages from ossec-maild and confirm that your provider allows outgoing SMTP connections.

Updating OSSEC

To update a source installation, download and verify the new release in the same way and run sudo ./install.sh from its directory. The installer detects the existing installation, asks whether to update it and whether to update the rules, and keeps your configuration. Back up /var/ossec/etc and /var/ossec/rules/local_rules.xml beforehand, and restart OSSEC afterwards so all daemons run the new binaries.

If you prefer packages, the OSSEC documentation describes RPM packages from the Atomicorp repository (ossec-hids with ossec-hids-server or ossec-hids-agent), which are then updated with dnf upgrade. Do not mix a source installation and the packages on the same host.

Frequently asked questions

Is OSSEC still maintained, or should I use Wazuh?

OSSEC is maintained by Atomicorp and receives releases; 4.4.1 was published in October 2026. Wazuh is a separate project that forked from OSSEC in 2015 and has since grown into a larger platform with its own server, indexer and web dashboard. Choose OSSEC when you want a small HIDS that mails alerts from a single host or a handful of agents. Consider Wazuh when you need a central dashboard, searchable alert history and compliance reporting across many machines, and can spare the extra resources for its server components.

What is the difference between OSSEC, OSSEC+ and Atomic OSSEC?

OSSEC is the free open source version installed here. According to the project site, OSSEC+ is free after registration and adds more rules and threat intelligence, and Atomic OSSEC is Atomicorp's commercial product with a management console and support.

Does active response work with firewalld?

Active response runs scripts from /var/ossec/active-response/bin; the default pair is host-deny, which adds the address to /etc/hosts.deny, and firewall-drop, which inserts a drop rule by calling /sbin/iptables. The script does not talk to firewalld directly, so make sure the iptables command exists (sudo dnf install iptables-nft provides it on the RHEL 9 family). Test it from an address you can afford to block and check /var/ossec/logs/active-responses.log to confirm that the block was applied and later removed on your system.

How do I monitor several servers?

Install one machine with the server type and the others with the agent type, register each agent on the server with /var/ossec/bin/manage_agents, import the generated key on the agent, and allow UDP port 1514 from the agents to the server.

Share story:

Continue reading other guides on How VPS.