A Debian-first guide to detecting, containing, recovering from, and reducing SSH brute force activity on exposed systems.
SSH brute force attacks happen when an external system repeatedly attempts to log in to your server using different usernames and passwords. This is one of the most common forms of background internet noise against publicly exposed Linux systems.
sudo journalctl -u ssh --since "1 hour ago"
sudo grep "Failed password" /var/log/auth.log
sudo grep "Failed password" /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr
If you see the same IP repeatedly, you are likely being targeted.
sudo ufw deny from <IP_ADDRESS>
sudo ufw status numbered
sudo grep "Accepted password" /var/log/auth.log
cut -d: -f1 /etc/passwd
If anything looks suspicious, review user accounts, rotate credentials, inspect SSH configuration, and check for persistence or unauthorized changes.
There is no single solution. Use multiple defensive layers depending on your environment.
sudo nano /etc/ssh/sshd_config
Set:
PasswordAuthentication no
Then restart SSH:
sudo systemctl restart ssh
This removes the ability to brute force passwords entirely.
ssh-copy-id user@server_ip
SSH keys are stronger than passwords and resistant to brute force attempts.
sudo apt update
sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
sudo fail2ban-client status
This can automatically block repeated failed login attempts.
If SSH is not needed publicly:
sudo ufw deny 22
Or restrict access to a trusted IP:
sudo ufw allow from <your_ip> to any port 22
Everything above can be done manually using built-in Debian tools, which is often the best choice for control, privacy, and cost efficiency.
Over time, this section may include carefully selected low-cost services or tools that make monitoring, firewall management, or remote administration easier. Any future recommendations will be kept practical, privacy-conscious, and relevant to the specific problem being discussed.
For now, the manual Debian-based workflow remains the primary recommendation.
All commands shown are based on Debian-based systems unless otherwise noted.