Security Handbook/Logging

From Gentoo Wiki
Jump to:navigation Jump to:search
Security Handbook
Security Concepts
General Security Guidance
Boot Path Security
Information Security
Mounting partitions
User and group limitations
File permissions
TCP wrappers
Kernel security
Network security
Securing services
Chrooting and virtual servers
Intrusion detection
Staying up-to-date

System administrators should choose between different system loggers in order to gain better viability into attacks.

Logging verbosity can be increased to catch warnings or errors that might indicate an ongoing attack or successful compromise. Attackers often scan or probe before directly attacking a targeted system, and these probes can be detected with proper logging.

It is also vital that log files are readable, well managed, and stored safely. Loggers should be chosen with consideration to security as well as the use case. There is no best logging utility for every job, although some are more versatile than others.

See also
See the logging meta article about available logging software on Gentoo.


Sysklogd is very commonly used with Linux and Unix systems in general. It has some log rotation facilities, but using logrotate in a cron job or systemd timer offers more features and control over how log files are rotated. The frequency of log rotation depends on many factors, such as load and capacity.

Below is the standard sysklogd configuration, located at, syslog.conf with some added features. The following cron and tty lines have been uncommented, and a remote logging server had been added.

Redundant storage of logs can help increase security, as logs will still exist if one log server is compromised and altered. Most attackers will try to erase their tracks, and redundant storage can make this significantly more difficult.
FILE /etc/syslog.conf


See also
See the Metalog article for more information.

Metalog by Frank Dennis is not able to log to a remote server, but it does have advantages when it comes to performance and logging flexibility. It can log by program name, urgency, facility (like sysklogd), and comes with regular expression matching with which you can launch external scripts when specific patterns are found. It is very good at taking action when needed.

The standard configuration is usually enough. To be notified by email whenever a password failure occurs use one of the following scripts.

For postfix:

FILE /usr/local/sbin/mail_pwd_failures.shPostfix
echo "$3" | mail -s "Warning (program : $2)" root

For netqmail:

FILE /usr/local/sbin/mail_pwd_failures.shNetqmail
echo "To: root
Subject:Failure (Warning: $2)
" | /var/qmail/bin/qmail-inject -f root

Remember to make the script executable by issuing chmod +x /usr/local/sbin/

Then uncomment the command line under "Password failures" in /etc/metalog/metalog.conf like:

FILE /etc/metalog/metalog.confMetalog
command  = "/usr/local/sbin/"


Syslog-ng provides many of the same features as sysklogd and metalog in a single package that does not run as root. It can filter messages based on level and content (like metalog), provide remote logging (like sysklogd), handle logs from syslog (or even Solaris). In addition to standard log handling features, syslog-ng can write to a TTY, execute programs, and act as a logging server.

Below is a copy of the gentoo-hardened configuration from /usr/share/doc/syslog-ng-4.0.1/syslog-ng.conf.gentoo.hardened.bz2, which can be deployed at /etc/syslog-ng/syslog-ng.conf:

FILE /etc/syslog-ng/syslog-ng.confSyslog-ng
syslog-ng is very easy to configure and misconfigure. Missing important logging options will result in records being lost.
Authenticated encryption must be used to sure logs are not being sniffed or tampered over a network, or on disk.

Log analysis with Logcheck

Of course, keeping logs alone is only half the battle. An application such as Logcheck can make regular log analysis much easier. logcheck is a script, accompanied by a binary called logtail, that runs from the cron daemon and checks the system logs against a set of rules for suspicious activity. It then mails the output to root's mailbox.

logcheck and logtail are part of the app-admin/logcheck package.

Logcheck uses four files to filter important log entries from the unimportant:

  • logcheck.hacking - Contains known hacking attack messages.
  • logcheck.violations - Contains patterns indicating security violations.
  • logcheck.violations.ignore - Contains keywords likely to be matched by the violations file, allowing normal entries to be ignored.
  • logcheck.ignore - matches those entries to be ignored.
Do not leave the logcheck.violations.ignore file empty. logcheck uses the grep utility to parse logs, some versions of which will take an empty file to mean wildcard. All violations would thus be ignored.