Run the commands below to download version 2.10
cd /tmp/ && wget http://cznic.dl.sourceforge.net/project/denyhost/denyhost-2.10/denyhosts-2.10.tar.gz
Next, run the commands below to extract it.
tar xzf denyhosts*.tar.gz
Then run the commands below to change into the extracted folder
cd DenyHosts*
Finally, run the commands below to install the program
sudo python setup.py install
After running the commands above, DenyHosts will be installed on your server but not fully configured You must manually configure the tool.
Copy the daemon file to the /etc/init.d/
directory.
sudo cp /usr/local/bin/daemon-control-dist /etc/init.d/denyhosts
Next, open the script (sudo vi /etc/init.d/denyhosts
) and make the below highlighted change
###############################################
#### Edit these to suit your configuration ####
###############################################
DENYHOSTS_BIN="/usr/local/bin/denyhosts.py"
DENYHOSTS_LOCK="/run/denyhosts.pid"
DENYHOSTS_CFG="/etc/denyhosts.conf"
PYTHON_BIN="/usr/bin/env python"
Once installed, its configured and ready to protect your servers. One thing most webmasters do is go white-list their own IP address so they don’t get blocked or banned mistakenly.
To white-list your own IP address, open the allow host file in the /etc/ directory and add your IP address you use to connect to the server.
sudo vi /etc/hosts.allow
Then add your IP address in the file and save it.
###############
####Example####
###############
sshd: 172.145.33.45
Restart DenyHosts by running the commands below.
sudo /etc/init.d/denyhosts start
DenyHosts configuration file is at /etc/denyhosts.conf
.