Tutorial

How To Install DenyHosts on Ubuntu 12.04

Published on June 15, 2012
How To Install DenyHosts on Ubuntu 12.04

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

About DenyHosts

DenyHosts is a security tool written in python that monitors server access logs to prevent brute force attacks on a virtual private server. The program works by banning IP addresses that exceed a certain number of failed login attempts.

Step One—Install Deny Hosts

DenyHosts is very easy to install on Ubuntu

 sudo apt-get install denyhosts

Once the program has finished downloading, denyhosts is installed and configured on your virtual private server.

Step Two—Whitelist IP Addresses

After you install DenyHosts, make sure to whitelist your own IP address. Skipping this step will put you at risk of locking yourself out of your own machine.

Open up the list of allowed hosts allowed on your VPS:

sudo nano /etc/hosts.allow

Under the description, add in any IP addresses that cannot afford to be banned from the server; you can write each one on a separate line, using this format:

sshd: 12.34.45.678

After making any changes, be sure to restart DenyHosts so that the new settings take effect on your virtual private server:

sudo /etc/init.d/denyhosts restart

Step Three—(Optional) Configure DenyHosts

DenyHosts is ready use as soon as the installation is over.

However if you want to customize the behavior of DenyHosts on your VPS, you can make the changes within the DenyHost configuration file:

sudo nano /etc/denyhosts.conf
By Etel Sverdlov

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

I don’t have an static IP address but I do you a dynamic service could I use a FQDN?

“sshd: 12.34.45.678” could use “sshd: myhouse.domainname.ext” instead?

Denyhots is no longer available on Ubuntu 14.04. Check this out.

When I attempted to restart denyhosts using the following line given in the tutorial, I got a command not found error:

sudo /etc/init.d/denyhosts restart

But the following command worked:

sudo service denyhosts restart

Should this be changed in the tutorial? Thanks for the article.

Dreni228, try a purge first, it will (it should) delete ALL traces of a package:

sudo apt-get purge fail2ban

and then reinstall again, maybe it will work

I have removed fail2ban from the server and then i tried to install again. But now, when i Enable the fail2ban i get this error: ERROR /etc/fail2ban/fail2ban.conf and /etc/fail2ban/fail2ban.local do not exist

How can i fix this?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
September 25, 2013

@mail85224: Just run <pre>sudo apt-get remove denyhosts</pre> :]

How ABOUT Uninstalling it for those who don’t know how?

How do I setup DenyHosts to send me an email? Via Sendmail for example.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.