Intrusion prevention security tool
According to the developers of
A short audit to your ssh log (/var/log/auth.log on ubuntu) will give you an idea of the number of hackers trying to gain access to your server. True, none of them was successful. But, it will be better to automatically prevent that hacker from a continuous attempt to gain access to your server.
Installing denyhosts
Run the following command to install
sudo apt update
sudo apt install denyhosts
Type ‘y’ and press Enter. When
Configure denyhosts
On Ubuntu 18.04 LTS the denyhosts configuration file is /etc/denyhosts.conf
To configure
sudo nano /etc/denyhosts.conf
The configuration file should look like the image below:
Now, know the meaning of each change we will be doing in the denyhosts configuration file.
DENY_THRESHOLD_INVALID
The default value for DENY_THRESHOLD_INVALID is 5. Meaning someone can try to ssh into your server using a guessed username(s) that is
DENY_THRESHOLD_VALID
DENY_THRESHOLD_VALID has a default value of 10. But this applies to only existing user accounts on the server. However, if an attempt to login with a valid user fail 10 times, the IP address attempting to establish connection with the server will be added to the /etc/hosts.deny file.
DENY_THRESHOLD_ROOT
DENY_THRESHOLD_ROOT has a default value of 1. This applies to invalid root login. Meaning you can only attempt to
AGE_RESET_VALID
AGE_RESET_VALID has a default value of 5 days. Meaning a failed login for an existing user will reset to 0 after 5 days.
AGE_RESET_ROOT
AGE_RESET_ROOT has a default of 25 days. That is, a failed root login can only be reset to 0 after 25 days.
AGE_RESET_INVALID
AGE_RESET_INVALID has a default of 10 days. Meaning a failed login for a non-existing user will reset to 0 after 10 days.
The configuration file has more option that you can explore. The configuration is also self-explanatory, just take your time and read about what each configuration setting is doing before customizing it. Good, we now have a good knowledge on how to configure
Moreover, there are some few other configurations in order not to lock our clients and ourselves out of the server.
White listing an IP address
The reason for whitelisting our IP address and if possible that of our client machine is to let the system know that the IPs given in the whitelist are no
However, in order to add an IP address to the whitelist, edit the /etc/hosts.allow file with the following command:
sudo nano /etc/hosts.allow
Then follow the following syntax :
sshd: IP1, IP2, ..., IPn
For instance:
sshd: 152.178.43.13, 162.128.78.16
Now, save and close the file.
Restart denyhosts Service
Use the following commands to restart denyhosts service:
sudo systemctl restart denyhosts.service
sudo systemctl enable denyhosts.service
Analyze log Events for denyhosts
Now, let’s list the current
sudo tail -f /var/log/denyhosts
Listing Blocked IPs
To list all IP addresses that have tried accessing the server via SSH run the command below:
sudo cat /etc/hosts.deny
However, denyhosts does not support IPv6.
Enable centralized synchronization support
Furthermore, let’s enable support for centralized synchronization. Hence, blocking hackers from many other servers. This website xmlrpc.denyhosts.net collect statistics from other servers running
SYNC_SERVER = http://xmlrpc.denyhosts.net:9911
After, save and close the file, then restart
sudo systemctl restart denyhosts.service
In a situation where you need to stop or start denyhosts, the following commands might be helpful:
sudo systemctl start denyhosts.service
sudo systemctl stop denyhosts.service
Finally, as the article
People reacted to this story.
Show comments Hide commentsA perfectly clear and concise reminder, thanks!
I hope the article was helpful