Home / Guides

Server guide

How to Check Auth Log for Suspicious Logins on Linux

This guide is for system administrators and hosting teams managing Linux VPS or dedicated servers. You will learn practical commands to scan authentication logs for failed attempts, successful logins from unknown IPs, and signs of brute-force attacks.

7 min readUpdated November 2026 by the RootManage teamWorks on Ubuntu, Debian, AlmaLinux and Rocky unless noted

The short answer

To check auth log for suspicious logins, use grep to filter /var/log/auth.log for 'Failed password' and 'Accepted' entries. Look for high volumes of failures from single IPs or successful logins from unexpected locations to identify potential compromises.

Why Auth Logs Matter for Server Security

Authentication logs, such as /var/log/auth.log on Debian‑based systems or /var/log/secure on RHEL‑based systems, record every login attempt, successful or not. By reviewing these logs regularly, administrators can spot patterns that indicate brute‑force attacks, credential stuffing, or compromised accounts before an attacker gains a foothold. Early detection lets you lock out offending IPs, enforce stronger authentication, or reset passwords, reducing the window of exposure and limiting potential damage.

Because auth logs capture timestamps, source IP addresses, usernames, and the authentication method used, they provide a forensic trail that is invaluable during incident response. Correlating repeated failed attempts with successful logins from the same source can reveal a successful breach that might otherwise go unnoticed. Consistent log monitoring also helps you verify that security controls like fail2ban or SSH key restrictions are functioning as intended.

  • Watch for repeated failed logins from the same IP.
  • Notice logins from unfamiliar geographic locations.
  • Check for login attempts using disabled or default accounts.
  • Identify usage of unexpected authentication methods.
terminal
grep -i 'failed' /var/log/auth.log && grep -i 'accepted' /var/log/auth.log

The command will list failed and successful login entries. Look for many failures from a single IP, logins at odd hours, or successful logins from accounts that should not be used. These clues point to potential brute‑force attempts or compromised credentials.

Locating Your Authentication Log Files

Authentication logs record every login attempt, successful or not, and are the primary source for spotting suspicious activity. Different Linux families store these logs in different locations. On Debian‑based systems, including Ubuntu, the file is typically /var/log/auth.log. On Red Hat‑based distributions such as CentOS, Fedora, and RHEL, the equivalent file is /var/log/secure. Knowing the correct path lets you quickly access the data you need without hunting through unrelated logs.

The log format is plain text and includes timestamps, usernames, source IP addresses, and the service used (ssh, sudo, su, etc.). When you open the file, look for repeated failures, logins from unfamiliar IPs, or logins at odd hours. These patterns often indicate brute‑force attacks or compromised credentials. Keeping the log files accessible but protected (readable only by root) ensures that you can audit activity while preventing tampering.

  • Check the distribution to choose the correct log path.
  • Use grep to filter for failed or successful logins.
  • Search for unusual source IP addresses or timestamps.
terminal
echo "Reading authentication log (example):" && sudo tail -n 20 /var/log/auth.log || sudo tail -n 20 /var/log/secure

The output will show the most recent login events. Look for lines containing Failed password, Invalid user, or Accepted password with IP addresses you do not recognize. Note the timestamps and source IPs for further investigation.

Basic Commands to Filter Failed Login Attempts

When reviewing authentication logs, focus on entries that indicate a failed password check for SSH. The system log file is usually /var/log/auth.log on Debian‑based distributions or /var/log/secure on RHEL‑based ones. Use grep to pull lines containing the keyword "Failed password"; this isolates attempts where the server rejected a credential. By filtering further for the SSH daemon identifier (often "sshd"), you narrow the output to only remote login attempts, making it easier to spot patterns or repeated failures from the same source.

After extracting the relevant lines, you can pull out the originating IP address with a second grep or awk pass. The IP appears after the phrase "from" in the log entry. Sorting and counting these addresses highlights the most frequent offenders, which are typically the targets of brute‑force attacks. Always run these commands in read‑only mode and verify the output before taking any action, such as blocking an IP or adjusting fail2ban rules.

  • Use grep with the exact phrase to avoid false positives.
  • Pipe to awk to extract the IP address field.
  • Sort and count duplicate IPs to find the most active sources.
  • Run commands as a non‑privileged user when possible; use sudo only for file access.
terminal
grep "Failed password" /var/log/auth.log | grep "sshd" | awk '{for(i=1;i<=NF;i++) if($i=="from") print $(i+1)}' | sort | uniq -c | sort -nr

The final list shows each source IP followed by the number of failed attempts. Look for IPs with a high count; these are likely brute‑force sources that may need to be blocked or monitored.

Identifying Successful Logins from Unknown Sources

To locate successful login events, search the authentication log for the keyword “Accepted”. On most Linux distributions the file is /var/log/auth.log or /var/log/secure. A typical line looks like: Accepted password for user from 203.0.113.45 port 54321 ssh2. Extract these lines and store them in a temporary file for analysis. This gives you a concise list of all successful logins, including the username, source IP address, and timestamp, which you can later compare against your known staff or service IP ranges.

Once you have the list, compare each source IP with a reference list of approved addresses. You can maintain this list in a simple text file, for example /etc/approved_ips.txt, containing one IP or CIDR block per line. Any IP that does not appear in the approved list should be flagged for further review. This cross‑reference helps you quickly spot logins from unknown locations, which may indicate compromised credentials or unauthorized access attempts.

  • Search for "Accepted" entries in the auth log.
  • Save the matching lines to a temporary file.
  • Create or update a file with approved IP addresses.
  • Use grep -v -F -f to filter out known IPs.
  • Investigate any remaining IPs that are not approved.
terminal
grep "Accepted" /var/log/auth.log > /tmp/successful.log
# Example list of approved IPs
cat <<EOF > /etc/approved_ips.txt
192.0.2.10
198.51.100.0/24
EOF
# Show log lines that are not from approved IPs
grep -v -F -f /etc/approved_ips.txt /tmp/successful.log

The output will show only those successful login entries whose source IP is not listed in your approved IP file. Review each remaining line for unexpected usernames, odd timestamps, or locations you do not recognize, and consider additional verification or password rotation for those accounts.

Handling Suspicious Findings Safely

When you spot a login that looks out of place in your auth logs, the first step is to preserve the state of the system. Create a snapshot or a full backup of the current disk image before making any changes. This ensures you can restore the server if an action has unintended side effects. Next, isolate the offending IP by adding a rule to the firewall that blocks traffic from that address. Use a rule that only drops packets from that IP, leaving the rest of the network unaffected.

If the suspicious login involves a user account that has root or sudo privileges, consider rotating the credentials immediately. Change the password for that account and, if possible, replace the SSH key used for authentication. After updating credentials, verify that all legitimate users can still log in. Finally, review the system for any signs of compromise, such as new cron jobs, unfamiliar binaries, or altered configuration files.

Common Mistakes to Avoid When Reading Logs

When you review the authentication log you should never delete or truncate active log files. Removing entries can erase evidence of a compromise and disrupt audit trails. Instead, create a copy or move the file to a safe location before editing. Also avoid using overly broad grep patterns like grep -i sshd that pull in every line. This can bury relevant failures behind a flood of unrelated entries. Always include context by adding -C 2 or -n to see line numbers and surrounding lines.

Another common pitfall is ignoring timestamp irregularities. If the system clock is skewed, log entries may appear out of order or with impossible dates. This can mask replay attacks or delay detection of brute‑force attempts. Verify the system clock with timedatectl and compare log timestamps with external time sources. If you see gaps or jumps, investigate the NTP configuration before drawing conclusions.

Setting Up Ongoing Log Monitoring

Configure log rotation to keep authentication logs manageable and ensure older entries are archived safely. On most Linux systems, edit /etc/logrotate.d/syslog or create a new file for /var/log/auth.log. Set a reasonable rotation interval, such as weekly, and retain a few copies (e.g., 4 weeks). This prevents the log file from growing indefinitely while still preserving enough history for forensic review. Remember to test the configuration with logrotate -d before enabling it.

Set up a lightweight alert that watches for a high number of failed login attempts. A simple cron job can grep the auth log for Failed password entries and count occurrences per hour. If the count exceeds a threshold you define, the script can send an email or push notification to the admin. This provides continuous visibility without requiring someone to manually scan the logs each day.

  • Use logrotate to compress and archive old auth logs.
  • Retain at least 4 weeks of logs for audit purposes.
  • Create a cron job that runs hourly to check failure counts.
  • Send alerts via email or a monitoring webhook when thresholds are crossed.
  • Document the threshold values and adjust them as traffic patterns change.
terminal
cat <<'EOF' > /etc/cron.hourly/auth-failure-alert
#!/bin/bash
THRESHOLD=10
COUNT=$(grep -c "Failed password" /var/log/auth.log)
if [ "$COUNT" -gt "$THRESHOLD" ]; then
  echo "High login failures: $COUNT" | mail -s "Auth Failure Alert" admin@example.com
fi
EOF

Check the mail inbox or notification channel for alerts. When you receive a message, verify the source IPs and timestamps in the auth log to determine if the failures are legitimate brute‑force attempts or misconfigurations.

If you would rather have engineers do this for you, see Linux server management, Windows server management or emergency malware cleanup.

Questions people ask

Which log file should I check on Ubuntu?

On Ubuntu the authentication log is stored in `/var/log/auth.log`. Open it with a text editor or view it with `less /var/log/auth.log` to review login attempts and related messages.

How do I see which IP addresses failed to log in?

Use `grep` to filter failures: `grep "Failed password" /var/log/auth.log` shows each failed attempt with the IP address after `from`. Count or list unique IPs with `awk '{print $11}' | sort | uniq -c` for a quick overview.

Is it safe to delete old auth logs?

Deleting old auth logs is acceptable for freeing space, but keep a recent copy. Use `logrotate` or manually move them: `sudo mv /var/log/auth.log /var/log/auth.log.old` and then `sudo touch /var/log/auth.log` and `sudo chmod 640 /var/log/auth.log` to recreate it safely.

What should I do if I see a successful login from an unknown IP?

If an unknown IP has a successful login, first verify if the account is legitimate. If not, change the password, consider disabling the account, and check for any unauthorized changes. Also review `lastlog` and `who` to see what was accessed.

Want a person to look at it?

Tell us what you see. We reply with what we think is wrong and what it would take to fix it.