Secure SSH with Fail2Ban
Securing the SSH server under Linux is crucial to close potential security gaps. A proven method to improve security is to use Fail2Ban, a software that automatically blocks malicious or suspicious connections.
Here are the steps to set up Fail2Ban to secure the SSH server:
- install Fail2Ban:
- open the terminal on your Linux system.
- run the command
sudo apt-get install fail2ban
to install Fail2Ban. - wait until the installation is complete.
- customize the configuration file:
- navigate to the directory
/etc/fail2ban/
. - open the file
jail.conf
orjail.local
(if available) with a text editor. - search for the section
[sshd]
and adjust the settings to your needs and addenabled=true
in this section to enable Fail2Ban. For example, you can set the maximum number of attemptsmaxretry
and the ban timebantime
. - save the changes and close the file.
- navigate to the directory
- restart the Fail2Ban service:
- run the command
sudo service fail2ban restart
to restart the Fail2Ban service. - check if the service has started successfully by checking the status with the command
sudo service fail2ban status
.
- run the command
Using Fail2Ban in conjunction with proper configuration provides an additional layer of protection against brute force attacks and other malicious activity on your SSH server.