In this tutorial we will show you how to install and configuration OSSEC on Ubuntu 14.04. For those of you who didn’t know, OSSEC is a free, open-source host-based intrusion detection system (HIDS). It performs log analysis, integrity checking, Windows registry monitoring, rootkit detection, time-based alerting, and active response. It provides intrusion detection for most operating systems, including Linux, OpenBSD, FreeBSD, Mac OS X, Solaris and Windows. OSSEC has a centralized, cross-platform architecture allowing multiple systems to be easily monitored and managed.
This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation OSSEC on a Ubuntu 14.04 server.
Install OSSEC on Ubuntu 14.04
Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.
sudo apt-get update
sudo apt-get upgrade
Step 2. Install LAMP (Linux, Apache, MariaDB, PHP) server.
A Ubuntu 14.04 LAMP server is required. If you do not have LAMP installed, you can follow our guide here.
Step 3. Installing OSSEC.
First thing to do is to go to OSSEC’s download page and download the latest stable version of OSSEC, At the moment of writing this article it is version 2.8.3:
Unpack the OSSEC archive to the document root directory in your server:
tar -xzf ossec-hids-2.8.3.tar.gz
Go back to the previous directory:
You can choose which options to enable/disable, but we recommend you to follow the output below. You can press enter if you want to go with the default choice (which is put in brackets) for every question asked:
OSSEC HIDS v2.8.3 Installation Script - http://www.ossec.net
You are about to start the installation process of the OSSEC HIDS.
You must have a C compiler pre-installed in your system.
If you have any questions or comments, please send an e-mail
to email@example.com (or firstname.lastname@example.org).
- System: Linux vps 2.6.32-042stab113.11
- User: root
- Host: vps.idroot.net
-- Press ENTER to continue or Ctrl-C to abort. --
1- What kind of installation do you want (server, agent, local, hybrid or help)? server
- Server installation chosen.
2- Setting up the installation environment.
- Choose where to install the OSSEC HIDS [/var/ossec]:
- Installation will be made at /var/ossec .
3- Configuring the OSSEC HIDS.
3.1- Do you want e-mail notification? (y/n) [y]:
- What's your e-mail address? email@example.com
- What's your SMTP server ip/host? smtp.example.com
3.2- Do you want to run the integrity check daemon? (y/n) [y]:
- Running syscheck (integrity check daemon).
3.3- Do you want to run the rootkit detection engine? (y/n) [y]:
- Running rootcheck (rootkit detection).
3.4- Active response allows you to execute a specific
command based on the events received. For example,
you can block an IP address or disable access for
a specific user.
More information at:
- Do you want to enable active response? (y/n) [y]:
- Active response enabled.
- By default, we can enable the host-deny and the
firewall-drop responses. The first one will add
a host to the /etc/hosts.deny and the second one
will block the host on iptables (if linux) or on
ipfilter (if Solaris, FreeBSD or NetBSD).
- They can be used to stop SSHD brute force scans,
portscans and some other forms of attacks. You can
also add them to block on snort events, for example.
- Do you want to enable the firewall-drop response? (y/n) [y]:
- firewall-drop enabled (local) for levels >= 6
- Default white list for the active response:
- Do you want to add more IPs to the white list? (y/n)? [n]:
3.5- Do you want to enable remote syslog (port 514 udp)? (y/n) [y]:
- Remote syslog enabled.
3.6- Setting the configuration to analyze the following logs:
-- /var/log/apache2/error.log (apache log)
-- /var/log/apache2/access.log (apache log)
- If you want to monitor any other file, just change
the ossec.conf and add a new localfile entry.
Any questions about the configuration can be answered
by visiting us online at http://www.ossec.net .
--- Press ENTER to continue ---
Next, press enter to continue with the installation which shouldn’t take more than 3 minutes. After everything is completed you will get:
- System is Debian (Ubuntu or derivative).
- Init script modified to start OSSEC HIDS during boot.
- Configuration finished properly.
- To start OSSEC HIDS:
- To stop OSSEC HIDS:
- The configuration can be viewed or modified at /var/ossec/etc/ossec.conf
Thanks for using the OSSEC HIDS.
If you have any question, suggestion or if you find any bug,
contact us at firstname.lastname@example.org or using our public maillist at
( http://www.ossec.net/main/support/ ).
More information can be found at http://www.ossec.net
--- Press ENTER to finish (maybe more information below). ---
- In order to connect agent and server, you need to add each agent to the server.
Run the 'manage_agents' to add or remove them:
Step 4. Configuring MariaDB for OSSEC.
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each steps carefully which will set root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
Configure it like this:
- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y
Next we will need to log in to the MariaDB console and create a database for the OSSEC. Run the following command:
mysql -u root -p
This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for OSSEC installation:
create database ossec;
grant all privileges on ossec.* to ossecuser@localhost identified by 'your_password';
By default OSSEC provides a schema for the database and it’s located in the src/os_dbd/ directory. Import it into your newly created ossec database:
mysql -u ossecuser -p ossec < src/os_dbd/mysql.schema
Now add the database config to OSSEC config file:
You can put the above lines anywhere in the <ossec_config> block:
Save and exit the file. Then, enable the database and restart OSSEC:
/var/ossec/bin/ossec-control enable database
Step 5. Installing OSSEC Web UI.
Install the OSSEC Web UI in Apache’s default document root. Enter the directory:
mv ossec-wui-master/ ossec/
Create a tmp directory inside and set the correct files ownership and permissions:
chown www-data: -R ossec/
chmod 666 /var/www/html/ossec/tmp
Step 6. Accessing OSSEC.
OSSEC will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://yourdomain.com/ossec or http://server-ip/ossec. If you are using a firewall, please open port 80 to enable access to the control panel.
Congratulation’s! You have successfully installed OSSEC. Thanks for using this tutorial for installing OSSEC on Ubuntu 14.04 system. For additional help or useful information, we recommend you to check the official OSSEC web site.