Sign In
Sign In

How to Monitor Authentication Logs in Ubuntu

How to Monitor Authentication Logs in Ubuntu
Hostman Team
Technical writer
Ubuntu
22.07.2024
Reading time: 5 min

System authentication logs are a crucial component of server security. They contain information about who attempted to log in and when and the results of these attempts. In Ubuntu, you can monitor and configure authentication logs to enhance system security.

Authentication logging in Ubuntu is managed through the system journal (systemd-journal), a centralized place for storing all system messages. The logs are stored in the file /var/log/auth.log.

Monitoring Authentication Logs in Ubuntu

Monitoring authentication logs in Ubuntu is a critical aspect of security. This guide outlines several methods for doing so.

The last Command

The last command in Ubuntu provides data on the latest system logins. To use it, open a terminal and type:

last

You can also use last with additional parameters to refine the output. For instance, to display users who logged in during a specific period, use the -s and -t parameters. To view information about a particular user, add the username after the command. To learn about all possible parameters and additional information, enter:

man last

Advantages of using the last command:

  • Access control: Analyzing system authentication logs helps monitor user activities and control access.

  • Unauthorized access detection: The last command can identify unauthorized access attempts, such as someone trying to log in with a false username.

  • Security improvement: Analyzing authentication logs can reveal security weaknesses, allowing for corrective measures.

The lastlog Command

The lastlog command in Ubuntu displays logs of the last successful user authentications. It shows information for each user, such as the date and time of the last authentication and the IP address used.

Syntax:

lastlog [options]

To learn about all available options, enter:

man lastlog

The lastlog command execution time depends on the number of registered users.

It provides a list of all users and their last successful authentication details.

When interpreting lastlog results, note each user's last successful authentication date and time. It might indicate a vulnerability or an unused account if they are outdated.

Additionally, lastlog results can be useful in identifying recently active users, especially if suspicious activity is detected.

The journalctl Utility

The journalctl utility allows you to view and analyze authentication logs in Ubuntu. It enables sorting entries by time, error level, and other parameters. To view log entries, run the following command in the terminal:

sudo journalctl -u ssh

This command displays all entries related to the SSH service. Use other parameters to search for specific entries. To explore the utility and its parameters further, enter:

man journalctl

The Fail2Ban Utility

Fail2Ban is a log-based protection program that analyzes authentication logs and blocks IP addresses attempting to log in with incorrect credentials. To install Fail2Ban, run:

sudo apt update
sudo apt install fail2ban

After installation, configure Fail2Ban to work with your authentication logs. The configuration file is located at /etc/fail2ban/jail.conf. Example configurations include:

  • Selecting which authentication logs to use.

  • Setting the frequency of checks for failed login attempts.

  • Specifying the ban period for blocked IP addresses.

Setting Up a Notification System for Failed Login Attempts

A notification system quickly informs about attempted breaches, enabling prompt protective measures. Use the logwatch utility, which analyzes system logs and emails reports of failed login attempts. To install logwatch, run:

sudo apt install logwatch

After installation, configure logwatch to send reports to a specified email address. The configuration file is located at /usr/share/logwatch/default.conf/logwatch.conf.

Analyzing Authentication Logs with Monitoring Tools

Monitoring tools help analyze authentication logs more effectively. They can automatically notify you of failed login attempts, perform real-time log analysis, and generate reports on significant events. Below are some popular monitoring tools:

Nagios

Nagios is a widely used monitoring tool that tracks system operations, including authentication logs. It can perform real-time analysis and generate reports on critical events like failed login attempts. Nagios can also be configured to send email or SMS alerts when issues are detected.

Zabbix

Zabbix is another popular system monitoring tool that collects information on failed login attempts and sends email or SMS alerts when problems are detected.

Splunk

Splunk is a powerful monitoring tool capable of real-time authentication log analysis and generating reports on significant events. Splunk allows for quick and efficient problem identification and resolution. Like the other tools, Splunk can send email or SMS alerts.

Conclusion

Monitoring authentication logs is a vital aspect of security in Ubuntu. This guide discussed several methods, including the use of the last and lastlog commands, and utilities such as journalctl, logwatch, and Fail2Ban. The choice of method depends on security requirements and user accessibility.

Ensure that the authentication log monitoring setup aligns with organizational security requirements, and regularly review logs to detect potential unauthorized access attempts.

Ubuntu
22.07.2024
Reading time: 5 min

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start
Email us