Mitigating SSH brute-force threats on Linux systems

Visualizing SSH Access

If you want a live dashboard of SSH traffic, use logtop [9]. It shows a real-time count of IPs hitting your SSH server (Figure 6):

sudo apt install logtop
sudo tail -F /var/log/auth.log | logtop
Figure 6: Perfect for spotting brute-force sources, logtop provides a real-time view of SSH login attempts sorted by IP.

For web-based visual dashboards, GoAccess [10] works well when used with logs parsed through a custom filter. While GoAccess is typically used for web logs, it can be adapted to show SSH trends with some log formatting.

Command-Level Tracking

For deeper visibility, install the Linux Audit Daemon (auditd) [11], which lets you log exactly what users do after connecting, including command usage and file access.

You can install auditd with

sudo apt install auditd audispd-plugins

To track all executed commands, use

sudo auditctl -a always,exit -F arch=b64 -S execve

Logs will appear in /var/log/audit/audit.log. Use ausearch and aureport to filter data.

You can also track file access with

sudo auditctl -w /etc/ssh/sshd_config -p wa -k ssh_config_watch

This alerts you to any changes to the SSH configuration file, even by root.

Final Checklist

Rate-limiting SSH traffic with iptables or ufw is a simple yet effective way to slow down attackers. Port knocking takes it a step further by hiding your SSH service entirely unless the right knock is received.

Combined with key authentication and tools like Fail2ban, these techniques form a layered defense strategy that can stop both casual bots and targeted brute-force attempts. Here's a summary checklist:

  • Disable password logins and enforce key-only authentication
  • Use Fail2ban to automatically block repeated failures
  • Rate-limit login attempts using iptables or ufw
  • Hide SSH using knockd and port knocking
  • Regularly review logs in /var/log/auth.log or secure
  • Set up daily reports with Logwatch
  • Enable real-time alerts using Logcheck or swatch
  • Use auditd to log command-level activity
  • Visualize access trends with logtop or dashboards

SSH is a powerful and flexible tool, but it's also a common target for attacks. Fortunately, Linux gives administrators all the tools they need to defend against brute-force attempts.

With the strategies covered in this article, from authentication hardening and firewall tuning to log-based detection and command auditing, you can turn SSH from a vulnerable gateway into a hardened fortress.

The Author

Neville Ondara is a systems engineer and Linux enthusiast who enjoys demystifying security tools and writing about real-world defensive strategies.

Buy this article as PDF

Download Article PDF now with Express Checkout
Price $2.95
(incl. VAT)

Buy Linux Magazine

Related content

  • Charly's Column

    Users log on to services such as SSH, ftp, SASL, POP3, IMAP, Apache htaccess, and many more using their names and passwords. These popular access mechanisms are a potential target for brute-force attacks. An attentive bouncer will keep dictionary attacks at bay.

  • Fail2ban

    Fail2ban is a quick to deploy, easy to set up, and free to use intrusion prevention service that protects your systems from brute force and dictionary attacks.

  • UFW Firewall

    UFW takes the complexity out of iptables, which is great for beginners and is even good for experienced users who want to keep it simple and avoid hidden mistakes.

  • Sshutout and Fail2ban

    Services that require a username and password for login are potential targets for dictionary attacks. Sshutout and Fail2ban introduce time penalties for invalid attempts.

  • Security Lessons: Password Storage

    High-performance graphics cards and proper storage can help keep your passwords secure.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News