Difference between revisions of "Denyhosts"

From Nuclear Physics Group Documentation Pages
Jump to navigationJump to search
m
m
Line 24: Line 24:
 
If you have been accidentally locked out of one of your hosts (because DenyHosts has added it to /etc/hosts.deny) you may have noticed that simply removing it from /etc/hosts.deny does not in itself correct the issue since DenyHosts keeps track of the attempts in the WORK_DIR files. In order to cleanse the address you will need to do the following:
 
If you have been accidentally locked out of one of your hosts (because DenyHosts has added it to /etc/hosts.deny) you may have noticed that simply removing it from /etc/hosts.deny does not in itself correct the issue since DenyHosts keeps track of the attempts in the WORK_DIR files. In order to cleanse the address you will need to do the following:
  
  #Stop DenyHosts
+
#Stop DenyHosts
  #Remove the IP address from /etc/hosts.deny
+
#Remove the IP address from /etc/hosts.deny
  #Edit WORK_DIR/hosts and remove the lines containing the IP address. Save the file.
+
#Edit WORK_DIR/hosts and remove the lines containing the IP address. Save the file.
  #Edit WORK_DIR/hosts-restricted and remove the lines containing the IP address. Save the file.
+
#Edit WORK_DIR/hosts-restricted and remove the lines containing the IP address. Save the file.
  #Edit WORK_DIR/hosts-root and remove the lines containing the IP address. Save the file.
+
#Edit WORK_DIR/hosts-root and remove the lines containing the IP address. Save the file.
  #Edit WORK_DIR/hosts-valid and remove the lines containing the IP address. Save the file.
+
#Edit WORK_DIR/hosts-valid and remove the lines containing the IP address. Save the file.
  #Edit WORK_DIR/user-hosts and remove the lines containing the IP address. Save the file.
+
#Edit WORK_DIR/user-hosts and remove the lines containing the IP address. Save the file.
  #Start DenyHosts  
+
#Start DenyHosts  
  
 
Note: Not all of the WORK_DIR files will contain the IP address so you may want to use grep to determine which files contain the IP address.  
 
Note: Not all of the WORK_DIR files will contain the IP address so you may want to use grep to determine which files contain the IP address.  
  
 
We have a script at '''/usr/local/bin/denyhosts-undeny.py''' on all the machines running denyhosts that should do this automatically. Just specify the host to undeny as the only argument, and it'll clean it all up for you. Currently, it only works on CentOS and RedHat, but it should be simple to add functionality for other distros.
 
We have a script at '''/usr/local/bin/denyhosts-undeny.py''' on all the machines running denyhosts that should do this automatically. Just specify the host to undeny as the only argument, and it'll clean it all up for you. Currently, it only works on CentOS and RedHat, but it should be simple to add functionality for other distros.

Revision as of 20:10, 15 June 2010

We run a python script called "denyhosts.py" on our servers. This script looks at failed login attempts and if there are too many will deny all further access from that system.

Installing Denyhosts

An RPM for denyhosts is located at: einstein:/root/Packages/DenyHosts-2.6-python2.4.noarch.rpm. Once installed follow these instructions:

  1. Copy from einstein the /etc/denyhosts.conf file.
  2. Copy from einstein the /etc/sysconfig/denyhosts file.
  3. Copy from einstein the /usr/bin/denyhosts-control file.
  4. Copy from einstein the /etc/init.d/denyhosts file.
  5. Execute "chkconfig --add denyhosts; chkconfig --level 345 denyhosts on
  6. Start it up: service denyhosts start

Alternatively, if you're running newer versions of Fedora (11+), or if you enable the [1] repositories on CentOS machines you can simply install denyhosts using the command

yum install denyhosts

And then just simply copy the /etc/denyhosts.conf from a machine with a working denyhosts install.

Faulty Denials

The Denyhosts FAQ gives these instructions for correcting erroneous denials:

If you have been accidentally locked out of one of your hosts (because DenyHosts has added it to /etc/hosts.deny) you may have noticed that simply removing it from /etc/hosts.deny does not in itself correct the issue since DenyHosts keeps track of the attempts in the WORK_DIR files. In order to cleanse the address you will need to do the following:

  1. Stop DenyHosts
  2. Remove the IP address from /etc/hosts.deny
  3. Edit WORK_DIR/hosts and remove the lines containing the IP address. Save the file.
  4. Edit WORK_DIR/hosts-restricted and remove the lines containing the IP address. Save the file.
  5. Edit WORK_DIR/hosts-root and remove the lines containing the IP address. Save the file.
  6. Edit WORK_DIR/hosts-valid and remove the lines containing the IP address. Save the file.
  7. Edit WORK_DIR/user-hosts and remove the lines containing the IP address. Save the file.
  8. Start DenyHosts

Note: Not all of the WORK_DIR files will contain the IP address so you may want to use grep to determine which files contain the IP address.

We have a script at /usr/local/bin/denyhosts-undeny.py on all the machines running denyhosts that should do this automatically. Just specify the host to undeny as the only argument, and it'll clean it all up for you. Currently, it only works on CentOS and RedHat, but it should be simple to add functionality for other distros.