
Brute Force SSH Attacks are among the most common threats to Linux servers. Cybercriminals use automated tools to guess passwords and gain unauthorized access. In this article, we’ll explore effective strategies to safeguard your Linux server from these attacks.
sudo nano /etc/ssh/sshd_configPermitRootLogin yesPermitRootLogin nosudo systemctl restart sshdcd ~/.ssh && ssh-keygen -t rsa -b 4096 ssh-copy-id user@your_server_ipsudo nano /etc/ssh/sshd_configPasswordAuthentication yesto
PasswordAuthentication noFinally, restart SSH to apply the changes:
sudo systemctl restart sshdsudo apt install fail2bansudo nano /etc/fail2ban/jail.localAdd the following lines:
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 15d sudo systemctl start fail2ban
sudo systemctl enable fail2bansudo fail2ban-client status sshdsudo fail2ban-client set sshd banip <IP>Replace
<IP>with the actual IP address you want to ban.
sudo fail2ban-client set sshd unbanip <IP>Replace
<IP>with the IP address you wish to unban.
Regularly reviewing login attempts can help you identify and respond to potential threats quickly.
/var/log/auth.log for unauthorized access attempts:sudo tail -f /var/log/auth.logYou can also view recent activity with the following command:
sudo journalctl --since "5 minute ago"