Configure intrusion detection with OSSEC and Wazuh for real-time security monitoring

Intermediate 45 min Apr 16, 2026 196 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up comprehensive host-based intrusion detection with OSSEC HIDS and Wazuh manager for real-time security monitoring, file integrity checking, and automated threat response across your infrastructure.

Prerequisites

  • Server with at least 4GB RAM
  • Root or sudo access
  • Basic understanding of Linux system administration
  • Email server or SMTP relay for notifications

What this solves

OSSEC HIDS (Host-based Intrusion Detection System) combined with Wazuh provides comprehensive real-time security monitoring for your servers. This setup detects unauthorized file changes, monitors system logs for suspicious activity, and automatically responds to security threats through active response rules.

Step-by-step installation

Update system packages

Start by updating your package manager and installing required dependencies for the security monitoring stack.

sudo apt update && sudo apt upgrade -y
sudo apt install -y curl apt-transport-https lsb-release gnupg2
sudo dnf update -y
sudo dnf install -y curl yum-utils

Add Wazuh repository

Add the official Wazuh repository to install the latest stable version with security updates and patches.

curl -s https://packages.wazuh.com/key/GPG-KEY-WAZUH | gpg --no-default-keyring --keyring gnupg-ring:/usr/share/keyrings/wazuh.gpg --import && chmod 644 /usr/share/keyrings/wazuh.gpg
echo "deb [signed-by=/usr/share/keyrings/wazuh.gpg] https://packages.wazuh.com/4.x/apt/ stable main" | sudo tee -a /etc/apt/sources.list.d/wazuh.list
sudo apt update
sudo rpm --import https://packages.wazuh.com/key/GPG-KEY-WAZUH
cat > /etc/yum.repos.d/wazuh.repo << EOF
[wazuh]
gpgcheck=1
gpgkey=https://packages.wazuh.com/key/GPG-KEY-WAZUH
enabled=1
name=EL-\$releasever - Wazuh
baseurl=https://packages.wazuh.com/4.x/yum/
protect=1
EOF

Install Wazuh manager

Install the Wazuh manager which will serve as the central server for collecting and analyzing security events from OSSEC agents.

sudo apt install -y wazuh-manager
sudo dnf install -y wazuh-manager

Install OSSEC agent locally

Install the OSSEC agent on the same server to monitor local system activity and demonstrate the manager-agent communication.

sudo apt install -y wazuh-agent
sudo dnf install -y wazuh-agent

Configure Wazuh manager

Configure the main Wazuh manager settings including alert levels, email notifications, and log analysis rules.


  
    yes
    localhost
    wazuh@example.com
    admin@example.com
    12
    alerts.log
    10m
    0
  

  
    3
    7
  

  
    secure
    1514
    udp
  

  
    no
    1515
    no
    yes
    yes
    HIGH:!ADH:!EXP:!MD5:!RC4:!3DES:!CAMELLIA:@STRENGTH
  

Configure file integrity monitoring

Set up real-time file integrity monitoring for critical system directories and configuration files.

  
    no
    300
    yes
    no
    yes
    ^/proc
    ^/sys
    /var/log
    
    
    /etc,/usr/bin,/usr/sbin
    /bin,/sbin
    
    
    /var/www
    
    
    /etc/passwd,/etc/shadow,/etc/group
    /etc/hosts,/etc/ssh/sshd_config
  

Configure log monitoring

Set up comprehensive log file monitoring for system authentication, web server access, and security events.

  
    syslog
    /var/log/auth.log
  

  
    syslog
    /var/log/syslog
  

  
    syslog
    /var/log/dpkg.log
  

  
    apache
    /var/log/apache2/access.log
  

  
    apache
    /var/log/apache2/error.log
  

  
    nginx
    /var/log/nginx/access.log
  

  
    nginx
    /var/log/nginx/error.log
  

Configure active response

Set up automated response actions to block IP addresses after multiple failed login attempts and other suspicious activities.

  
    firewall-drop
    firewall-drop
    yes
  

  
    host-deny
    host-deny
    yes
  

  
    route-null
    route-null
    yes
  

  
    no
    firewall-drop
    local
    5720
    600
  

  
    no
    firewall-drop
    local
    5763
    600
  

  
    no
    host-deny
    local
    5720
    600
  

Configure agent connection

Configure the OSSEC agent to connect to the local Wazuh manager for demonstration purposes.


  
    
      
127.0.0.1
1514 udp
ubuntu, ubuntu24, ubuntu24.04 10 60 yes aes

Set proper file permissions

Configure secure file permissions for OSSEC configuration files and directories. The ossec user needs read access to configuration files, while sensitive files require restricted access.

sudo chown root:ossec /var/ossec/etc/ossec.conf
sudo chmod 640 /var/ossec/etc/ossec.conf
sudo chown -R ossec:ossec /var/ossec/logs
sudo chmod 750 /var/ossec/logs
sudo chown -R root:ossec /var/ossec/etc
sudo chmod -R 640 /var/ossec/etc/*
Never use chmod 777. It gives every user on the system full access to your files. Instead, fix ownership with chown and use minimal permissions like 640 for config files and 750 for directories.

Start and enable services

Enable both the Wazuh manager and agent services to start automatically on boot and begin monitoring.

sudo systemctl enable --now wazuh-manager
sudo systemctl enable --now wazuh-agent
sudo systemctl status wazuh-manager
sudo systemctl status wazuh-agent

Register the agent

Register the local OSSEC agent with the Wazuh manager using the agent registration process.

sudo /var/ossec/bin/agent-auth -m 127.0.0.1 -p 1515
sudo systemctl restart wazuh-agent

Configure email notifications

Set up email notifications by configuring a local mail server or external SMTP relay for security alerts.

sudo apt install -y postfix mailutils
sudo systemctl enable --now postfix
sudo dnf install -y postfix mailx
sudo systemctl enable --now postfix

Install Wazuh dashboard

Install the Wazuh dashboard for web-based security event visualization and management. First, install the required Elasticsearch and Wazuh indexer.

sudo apt install -y wazuh-indexer wazuh-dashboard
sudo systemctl enable --now wazuh-indexer
sudo systemctl enable --now wazuh-dashboard
sudo dnf install -y wazuh-indexer wazuh-dashboard
sudo systemctl enable --now wazuh-indexer
sudo systemctl enable --now wazuh-dashboard

Configure firewall rules

Open required ports for Wazuh manager communication and dashboard access while maintaining security.

sudo ufw allow 1514/udp comment 'Wazuh agent communication'
sudo ufw allow 1515/tcp comment 'Wazuh agent registration'
sudo ufw allow 443/tcp comment 'Wazuh dashboard HTTPS'
sudo ufw allow 5601/tcp comment 'Wazuh dashboard HTTP'
sudo ufw reload
sudo ufw status numbered

Verify your setup

Test the intrusion detection system by checking service status, agent connectivity, and generating test alerts.

sudo systemctl status wazuh-manager wazuh-agent wazuh-indexer wazuh-dashboard
sudo /var/ossec/bin/agent_control -l
sudo tail -f /var/ossec/logs/alerts/alerts.log

Generate test alert

echo "test" | sudo tee -a /etc/passwd sudo rm /tmp/test_file 2>/dev/null || echo "File not found - this will generate an alert"

Check agent status

sudo /var/ossec/bin/agent_control -s

View recent alerts

sudo /var/ossec/bin/agent_control -a 000

Configure advanced monitoring rules

Create custom detection rules

Add custom rules for detecting specific security threats relevant to your environment.


  
    5720
    Failed password
    5
    300
    Multiple SSH authentication failures
    authentication_failures
  

  
    5551
    su: FAILED
    3
    120
    Multiple failed su attempts - possible privilege escalation
    privilege_escalation
  

  
    550
    Integrity checksum changed
    Critical system file modified
    file_integrity
  

Configure CIS benchmarks monitoring

Enable CIS (Center for Internet Security) benchmark compliance monitoring for your operating system.

  
    yes
    yes
    12h
    yes
    
    
      cis_ubuntu2204.yml
      cis_debian11.yml
      sca_unix_audit.yml
    
  

Restart services to apply changes

Restart the Wazuh manager to load the new custom rules and security configuration policies.

sudo systemctl restart wazuh-manager
sudo systemctl restart wazuh-agent
sudo tail -f /var/ossec/logs/ossec.log

Dashboard access and integration

Access the Wazuh dashboard at https://your-server-ip:443 or http://your-server-ip:5601. The default credentials are admin/admin, which you should change immediately after first login. The dashboard provides real-time security event visualization, compliance reporting, and alert management capabilities that integrate with your existing monitoring infrastructure like Prometheus and Grafana monitoring.

Common issues

SymptomCauseFix
Agent not connecting to managerFirewall blocking port 1514sudo ufw allow 1514/udp && sudo ufw reload
File integrity alerts not workingIncorrect directory permissionssudo chown -R ossec:ossec /var/ossec && sudo chmod 750 /var/ossec
Email alerts not sendingSMTP server not configuredConfigure postfix: sudo dpkg-reconfigure postfix
Dashboard not accessibleElasticsearch not runningsudo systemctl start wazuh-indexer && sudo systemctl status wazuh-indexer
High false positive alertsDefault rules too sensitiveTune alert levels in /var/ossec/etc/ossec.conf and restart services
Active response not blocking IPsFirewall integration not workingCheck /var/ossec/active-response/bin/firewall-drop permissions and iptables rules
Agent registration failsAuthentication key mismatchsudo /var/ossec/bin/manage_agents and regenerate keys

Next steps

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle infrastructure security hardening for businesses that depend on uptime. From initial setup to ongoing operations.