Skip to content

Instantly share code, notes, and snippets.

@tommybutler
Created October 12, 2013 19:04
Show Gist options
  • Save tommybutler/6953648 to your computer and use it in GitHub Desktop.
Save tommybutler/6953648 to your computer and use it in GitHub Desktop.
Remove an IP address ban that has been blocked by denyhosts
#!/bin/bash
# denyhosts-remove.sh
#
# AUTHOR: Tommy Butler, email: $ echo YWNlQHRvbW15YnV0bGVyLm1lCg==|base64 -d
# VERSION: 1.0
#
# SUMMARY:
# Use this script to Remove an IP address ban that has been errantly blacklisted
# by denyhosts - the ubiquitous and unforgiving brute-force attack protection
# service so often used on Linux boxen.
#
# INSTALL:
# Usage: Put this script somewhere in your $PATH, and execute it as root or
# with sudo. Call it directly or with an IP address argument. Multiple IP
# address arguments are not supported. You'll need to `chmod +x` it first.
#
# LICENSE:
# GNU GPL 1.0
# Copyright 2011 Tommy Butler, All rights reserved
BASE_PATH="/var/lib/denyhosts";
IP=$1
if [[ "`/usr/bin/id -u`" != "0" ]]; then
echo "Run this script as root or with sudo or app can't run correctly. Aborted."
exit 1;
fi
cd $BASE_PATH
if [[ "`pwd`" != "$BASE_PATH" ]]; then
echo "Couldn't cd to $BASE_PATH. Abort."
exit 1;
fi
if [[ "$IP" == "" ]]; then
echo "Enter the IP address you want to un-ban"
read IP
fi
if [[ "$IP" == "" ]]; then
echo "No IP address given. Abort."
exit 1;
fi
/etc/init.d/denyhosts stop
/usr/bin/perl -pi -e "s/^.*?$IP.*\n//g" /etc/hosts.deny *
/etc/init.d/denyhosts start
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment