Set up OSSEC agent deployment and centralized management with automated configuration

Intermediate 45 min Apr 15, 2026 848 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Deploy and manage OSSEC Host-based Intrusion Detection System (HIDS) across multiple servers with centralized monitoring, automated agent configuration, and real-time security event processing for enterprise-scale infrastructure protection.

Prerequisites

  • Root or sudo access on all target servers
  • Network connectivity between OSSEC server and agents
  • SSH key authentication configured
  • Email server for alert notifications
  • Firewall configured to allow UDP port 1514

What this solves

OSSEC provides real-time security monitoring, log analysis, and intrusion detection across distributed infrastructure. This tutorial establishes a centralized OSSEC server that manages multiple agents, automates deployment processes, and provides unified security monitoring for your entire server fleet.

Step-by-step installation

Update system packages and install dependencies

Update your package manager and install required build dependencies for OSSEC compilation.

sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential gcc make libevent-dev zlib1g-dev libssl-dev libpcre2-dev wget
sudo dnf update -y
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y libevent-devel zlib-devel openssl-devel pcre2-devel wget

Download and extract OSSEC source

Download the latest OSSEC release and extract it to prepare for installation.

cd /tmp
wget https://github.com/ossec/ossec-hids/archive/3.7.0.tar.gz
tar -xzf 3.7.0.tar.gz
cd ossec-hids-3.7.0

Install OSSEC server

Run the installation script with server configuration to enable centralized management capabilities.

sudo ./install.sh

During installation, select these options:

  • Installation type: server
  • Installation directory: /var/ossec (default)
  • Email notification: y and provide admin email
  • SMTP server: provide your mail server or localhost
  • Enable firewall response: y
  • Enable system integrity check: y
  • Enable rootkit detection: y
  • Enable active response: y

Configure OSSEC server settings

Customize the main OSSEC configuration for centralized management and security monitoring.


Configure firewall for OSSEC communication

Open the required port for agent-server communication and configure firewall rules.

sudo ufw allow 1514/udp comment "OSSEC agent communication"
sudo ufw reload
sudo firewall-cmd --permanent --add-port=1514/udp --zone=public
sudo firewall-cmd --reload

Start and enable OSSEC server

Start the OSSEC server and configure it to start automatically on boot.

sudo /var/ossec/bin/ossec-control start
sudo systemctl enable ossec

Create agent deployment automation script

Create a script to automate OSSEC agent installation and key management across multiple hosts.

#!/bin/bash

# OSSEC Agent Deployment Script
# Usage: ./deploy-ossec-agent.sh 

set -euo pipefail

# Configuration
OSSEC_SERVER="203.0.113.10"  # Replace with your OSSEC server IP
OSSEC_VERSION="3.7.0"
SSH_KEY="/root/.ssh/id_rsa"  # Path to SSH private key

# Validate arguments
if [ $# -ne 3 ]; then
    echo "Usage: $0 

Make deployment script executable and configure SSH

Set proper permissions for the deployment script and configure SSH key authentication.

sudo chmod 755 /usr/local/bin/deploy-ossec-agent.sh

# Generate SSH key if not exists
if [ ! -f /root/.ssh/id_rsa ]; then
    sudo ssh-keygen -t rsa -b 4096 -f /root/.ssh/id_rsa -N ""
fi

# Display public key for distribution to target hosts
echo "Copy this public key to target servers:"
sudo cat /root/.ssh/id_rsa.pub
Note: Copy the displayed SSH public key to the ~/.ssh/authorized_keys file on each target server you want to deploy agents to.

Create centralized management script

Create a script to manage multiple agents from the central server.

#!/bin/bash

# OSSEC Agent Management Script
# Usage: ./manage-ossec-agents.sh 
# Actions: list, status, restart-all, remove

set -euo pipefail

ACTION="${1:-}"
AGENT_NAME="${2:-}"

case "$ACTION" in
    "list")
        echo "=== Active OSSEC Agents ==="
        sudo /var/ossec/bin/list_agents
        ;;
    
    "status")
        echo "=== OSSEC Server Status ==="
        sudo /var/ossec/bin/ossec-control status
        echo ""
        echo "=== Recent Alerts ==="
        sudo tail -n 20 /var/ossec/logs/alerts/alerts.log
        ;;
    
    "restart-all")
        echo "[INFO] Restarting OSSEC server"
        sudo /var/ossec/bin/ossec-control restart
        echo "[INFO] OSSEC server restarted"
        ;;
    
    "remove")
        if [ -z "$AGENT_NAME" ]; then
            echo "Usage: $0 remove 

Make management script executable

Set proper permissions for the management script.

sudo chmod 755 /usr/local/bin/manage-ossec-agents.sh

Deploy agents to target servers

Use the deployment script to install agents on your target servers.

# Deploy to a web server
sudo /usr/local/bin/deploy-ossec-agent.sh web01 203.0.113.20 root

# Deploy to a database server
sudo /usr/local/bin/deploy-ossec-agent.sh db01 203.0.113.21 root

# Deploy to an application server
sudo /usr/local/bin/deploy-ossec-agent.sh app01 203.0.113.22 ubuntu

Configure log monitoring and alerting

Enhance the OSSEC configuration to monitor additional log sources and configure custom alerting rules.


Configure email alerting

Set up email notifications for critical security events.

  

  

Add this configuration within the main ossec_config block and restart OSSEC.

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

Verify your setup

Confirm that your OSSEC server is running and agents are connected properly.

# Check OSSEC server status
sudo /var/ossec/bin/ossec-control status

# List connected agents
sudo /usr/local/bin/manage-ossec-agents.sh list

# View recent alerts
sudo tail -n 20 /var/ossec/logs/alerts/alerts.log

# Check server statistics
sudo /usr/local/bin/manage-ossec-agents.sh stats

# Test agent connectivity
sudo /var/ossec/bin/agent_control -lc

# Monitor real-time alerts
sudo tail -f /var/ossec/logs/alerts/alerts.log

Configure advanced monitoring rules

Create custom monitoring profiles

Configure specific monitoring rules for different server types.

# Web server specific monitoring

Automated install script

Run this to automate the entire setup

Don't want to manage this yourself?

We handle infrastructure for businesses that depend on uptime. Fully managed, with one fixed contact who knows your setup.

You get one fixed contact who knows your setup

Rotterdam 04:51 · reachable in a message, no ticket form