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 fail2banto install Fail2Ban. - wait until the installation is complete.
- customize the configuration file:
- navigate to the directory
/etc/fail2ban/. - open the file
jail.conforjail.local(if available) with a text editor. - search for the section
[sshd]and adjust the settings to your needs and addenabled=truein this section to enable Fail2Ban. For example, you can set the maximum number of attemptsmaxretryand the ban timebantime. - save the changes and close the file.
- navigate to the directory
- restart the Fail2Ban service:
- run the command
sudo service fail2ban restartto 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.