Un-denying a Denied Host

A great guy named Nicholas put out an easy to use script to unban an ip address that’s been banned by denyhosts. Here’s me gushing with praise since I could be lazy and not have to write it, along with the script so you can benefit from his contribution as well.

A big thanks to Nicholas Avenell, who solved a problem I’ve been having for a while: How to remove a host that denyhosts has banned. Yes, the FAQ for denyhosts has the manual steps listed, but Nicholas scripted it. And it works great.

Copy Nicholas’s script into a file, give it execute permissions, and run it with root privileges passing in the IP address you’d like to unban:

#/bin/sh
REMOVE=$1
/etc/init.d/denyhosts stop
cd /var/lib/denyhosts
for THISFILE in hosts hosts-restricted hosts-root hosts-valid users-hosts;
do
mv $THISFILE /tmp/;
cat /tmp/$THISFILE | grep -v $REMOVE > $THISFILE;
rm /tmp/$THISFILE;
done;
mv /etc/hosts.deny /tmp/
cat /tmp/hosts.deny | grep -v $REMOVE > /etc/hosts.deny;
rm /tmp/hosts.deny
/etc/init.d/denyhosts start

Nicholas, you rule. Thanks.

One thought on “Un-denying a Denied Host”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.