WEBTOOLIST.
STATIC WEB PLATFORM
NO ACCOUNTS / NOTHING TO INSTALL

$ webtoolist --script failed-login-report

Failed Login Report

Summarise recent failed SSH logins by source address.

category Security shell Bash 4+ updated 2026-08-24
sshloginssecuritylogs
Safety notes
  • Read-only: reads journal entries only.
  • IP addresses in logs can include spoofed or shared NAT addresses; treat them as leads, not proof.
commands involved: sshcredentials

Dependencies: journalctl, awk, sort

Usage

  • Run on a systemd host with journald retaining SSH logs.
  • Set SINCE (journalctl syntax) to change the window, default ‘24 hours ago’.

Script

#!/usr/bin/env bash
set -euo pipefail

since="${SINCE:-24 hours ago}"

echo "Failed SSH logins since: $since"
journalctl -u ssh -u sshd --since "$since" --no-pager 2>/dev/null \
  | awk '/Failed password for/ {for (i=1;i<=NF;i++) if ($i=="from") print $(i+1)}' \
  | sort | uniq -c | sort -rn | head -n 20

echo
echo "Accepted logins in the same window:"
journalctl -u ssh -u sshd --since "$since" --no-pager 2>/dev/null \
  | awk '/Accepted (password|publickey) for/ {print $1, $2, $3, $9, $11}' \
  | tail -n 20

Example

sudo ./failed-login-report
SINCE='7 days ago' sudo ./failed-login-report

Notes

  • On Debian/Ubuntu the unit is usually ssh; on RHEL-family systems it is sshd.
  • A high count from one address is a prompt to check fail2ban or firewall rules, not to block automatically.

Related scripts

SSH Hardening Audit

Inspect sshd configuration for common risky settings without changing anything.

Security

File Permission Audit

Find world-writable files and directories, excluding known-safe locations.

Security

Batch Command Runner

Run one command on a list of SSH hosts, sequentially, with clear output.

Automation

Failed Service Report

List systemd units that are failed or restarting, with recent log lines.

System Administration