A lightweight system for monitoring authentication events on pfSense firewalls with email notifications, including SSH connections and SSHGuard blocking events.
Note: This is a fork of ngfblog/pfLoginTracker.
Changes in this fork:
- Removed Gotify support (email only).
- Added monitoring for OpenVPN logins (success and failure).
- Updated log parsing to support RFC 5424 / RFC 3339 timestamp formats (including year).
- Fixed duplicate email notifications.
This project provides two shell scripts that work together to:
- Monitor the pfSense authentication log file (
/var/log/auth.log) for successful and failed login attempts - Track SSH connections and SSHGuard blocking activities
- Send notifications via:
- Email (using pfSense's built-in notification system)
- Track successful and failed login attempts
- Monitor SSH connections to your pfSense system
- Receive alerts when SSHGuard blocks suspicious IP addresses
- Send email notifications using your pfSense SMTP settings
- Keep track of processed log entries to avoid duplicate notifications
- Configurable for your environment
- A pfSense firewall with shell access
- SMTP configuration set up in pfSense System > Advanced > Notifications
- Log Message Format set to syslog (RFC 5424, with RFC 3339 microsecond-precision timestamps) in Status > System Logs > Settings.
Important: After changing this setting, you must click the Reset Log Files button on the same page for the changes to take effect.
Tip: You can execute the shell commands listed below either via SSH or by using the Diagnostics > Command Prompt feature in the pfSense WebGUI.
-
Create a directory for the scripts:
mkdir -p /root/Scripts -
Install the scripts using one of the following methods:
Option A: Automatic Download (Recommended for Command Prompt)
fetch https://raw.githubusercontent.com/useblocks/pfLoginTracker/refs/heads/main/check_pfsense_login.sh -o /root/Scripts/check_pfsense_login.sh fetch https://raw.githubusercontent.com/useblocks/pfLoginTracker/refs/heads/main/email_auth_alert.sh -o /root/Scripts/email_auth_alert.shOption B: Manual Creation (via SSH)
Create
check_pfsense_login.sh:vi /root/Scripts/check_pfsense_login.sh(Copy contents from
check_pfsense_login.shin this repository)Create
email_auth_alert.sh:vi /root/Scripts/email_auth_alert.sh(Copy contents from
email_auth_alert.shin this repository) -
Make both scripts executable:
chmod +x /root/Scripts/check_pfsense_login.sh chmod +x /root/Scripts/email_auth_alert.sh -
Install the
Cronpackage via System > Package Manager if it is not already installed. Then set up a cron job to run the monitoring script periodically. Add the following to Services > Cron:- Command:
/root/Scripts/check_pfsense_login.sh - User:
root - Schedule:
*/5 * * * *(runs every 5 minutes)
- Command:
The script uses pfSense's built-in notification system, so make sure your SMTP settings are correctly configured in pfSense at:
System > Advanced > Notifications > E-Mail
check_pfsense_login.shscans the auth.log file for new entries since the last check- The script detects different types of events:
- Standard authentication successes and failures
- SSH connection attempts
- SSHGuard blocking actions
- When it finds an event, it extracts the relevant information (username, IP address)
- It calls
email_auth_alert.shwith these details email_auth_alert.shsends notifications to email
The system now monitors and alerts on:
- Authentication Success: Successful logins to the pfSense web interface
- Authentication Failure: Failed login attempts to the pfSense web interface
- SSH Connection: When someone connects to your pfSense system via SSH
- SSHGuard Block: When SSHGuard detects and blocks suspicious IP addresses
You can customize the scripts to:
- Change notification priorities
- Add geo-location information for IP addresses
- Filter out specific users or IP addresses
- Adjust the notification format
You can manually test the alert script to verify that email notifications are working correctly. Run the following command via SSH or in Diagnostics > Command Prompt:
/root/Scripts/email_auth_alert.sh "testuser" "127.0.0.1" "Test Event" "Test Service"Check the system logs for error messages:
tail -f /var/log/system.log | grep pfsense_auth_alert
MIT License - See LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Give the project a ⭐ on GitHub and spread the word!