• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

How to Block Brute Force SSH with DenyHosts

AnonyViet by AnonyViet
January 24, 2023
in Network
0

DenyHosts is open source software that helps block brute force attacks with SSH login to help protect your Linux Server more securely. This is a fairly lightweight Tool and very simple to use, just exceed the number of incorrect logins, that IP will be blocked, unable to detect Key, Password SSH.

Join the channel Telegram of the AnonyViet 👉 Link 👈

How to Block Brute Force SSH with DenyHosts

DenyHosts monitors and analyzes SSH Logs for false logins, dictionary-based attacks, and attacks. brute force attack by blocking the original IP addresses and adding an entry to the file /etc/hosts.deny on the server and prevent the IP address from making any further login attempts.

DenyHosts is a very essential tool for all Linux based systems, especially when we allow ssh login to remote Linux servers.

In this article, I will show you how to install and configure DenyHosts on RHEL-based Linux distributions like Fedora, CentOS, Rocky Linux, and AlmaLinux.

How to Install DenyHosts in Linux

By default, the DenyHosts tool is not built-in to the Linux system, we need to install it using a third-party EPEL repository. After adding the repository, install the DenyHosts package using the following yum command.

# yum install epel-release
# yum install denyhosts

Configure DenyHosts for IP addresses in Whitelist

After installing Denyhosts, make sure to whitelist your own IP address, so that it never gets blocked. To do this, open the file /etc/hosts.allow.

# vi /etc/hosts.allow

Below the description, add each IP address in a separate line that you don’t want to block.

#
# hosts.allow   This file contains access rules which are used to
#               allow or deny connections to network services that
#               either use the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
sshd: 172.16.25.125
sshd: 172.16.25.126
sshd: 172.16.25.127

Configure DenyHosts for email alerts

The main configuration file is located in /etc/denyhosts.conf. This file is used to send email notifications about suspected logins. Open this file with an editor vi.

# vi /etc/denyhosts.conf

Find the line ‘ADMIN_EMAIL’ and add your email address here to receive email notifications of suspicious logins (for multiple emails, use commas). Each variable is fully documented so configure it to your liking.

############ DENYHOSTS REQUIRED SETTINGS ############
SECURE_LOG = /var/log/secure
HOSTS_DENY = /etc/hosts.deny
BLOCK_SERVICE  = sshd
DENY_THRESHOLD_INVALID = 5
DENY_THRESHOLD_VALID = 10
DENY_THRESHOLD_ROOT = 1
DENY_THRESHOLD_RESTRICTED = 1
WORK_DIR = /var/lib/denyhosts
SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES
HOSTNAME_LOOKUP=YES
LOCK_FILE = /var/lock/subsys/denyhosts

############ DENYHOSTS OPTIONAL SETTINGS ############
ADMIN_EMAIL = [email protected]
SMTP_HOST = localhost
SMTP_PORT = 25
SMTP_FROM = DenyHosts <[email protected]>
SMTP_SUBJECT = DenyHosts Daily Report

############ DENYHOSTS OPTIONAL SETTINGS ############
DAEMON_LOG = /var/log/denyhosts
DAEMON_SLEEP = 30s
DAEMON_PURGE = 1h

Restart the DenyHosts service

When you’re done with the configuration, reboot denyhosts. We also add denyhosts into startup.

# chkconfig denyhosts on
# service denyhosts start

View DenyHosts logs

To view the diary denyhosts how many attackers and hackers are trying to access your server. Please use the following command:

# tail -f /var/log/secure
Nov 28 15:01:43 tecmint sshd[25474]: Accepted password for root from 172.16.25.125 port 4339 ssh2
Nov 28 15:01:43 tecmint sshd[25474]: pam_unix(sshd:session): session opened for user root by (uid=0)
Nov 28 16:44:09 tecmint sshd[25474]: pam_unix(sshd:session): session closed for user root
Nov 29 11:08:56 tecmint sshd[31669]: Accepted password for root from 172.16.25.125 port 2957 ssh2
Nov 29 11:08:56 tecmint sshd[31669]: pam_unix(sshd:session): session opened for user root by (uid=0)
Nov 29 11:12:00 tecmint atd[3417]: pam_unix(atd:session): session opened for user root by (uid=0)
Nov 29 11:12:00 tecmint atd[3417]: pam_unix(atd:session): session closed for user root
Nov 29 11:26:42 tecmint sshd[31669]: pam_unix(sshd:session): session closed for user root
Nov 29 12:54:17 tecmint sshd[7480]: Accepted password for root from 172.16.25.125 port 1787 ssh2

Remove blocked IP address from DenyHosts

If you want to remove that blocked IP address from denyhosts. You need to stop the tool.

# /etc/init.d/denyhosts stop

To remove or completely remove blocked IP address. You need to edit the following files and remove the IP address.

# vi /etc/hosts.deny
# vi /var/lib/denyhosts/hosts
# vi /var/lib/denyhosts/hosts-restricted
# vi /var/lib/denyhosts/hosts-root
# vi /var/lib/denyhosts/hosts-valid
# vi /var/lib/denyhosts/users-hosts

After removing the blocked IP address, restart the service.

# /etc/init.d/denyhosts start

The offending IP address has been added to all files in the directory /var/lib/denyhosts, so it is difficult to determine which file contains the offending IP address. One of the best ways to find out the IP address is to use the grep command. Example to find out IP address 172.16.25.125:

cd /var/lib/denyhosts
grep 172.16.25.125 *

Permanently whitelist IP addresses in DenyHosts

If you have a list of static IP addresses that you want to whitelist permanently. Please open the file /var/lib/denyhosts/allowed-hosts. Any IP addresses contained in this file will not be blocked by default.

# vi /var/lib/denyhosts/allowed-hosts

And add each IP address on each line separately. Then save and close the file.

# We mustn't block localhost
127.0.0.1
172.16.25.125
172.16.25.126
172.16.25.127

The article achieved: 5/5 – (100 votes)

Tags: BlockBruteDenyHostsForceSSH
Previous Post

Lesson 212: Reverse the list

Next Post

Tips to find other people’s information on the Internet

AnonyViet

AnonyViet

Related Posts

Is Renting a Cheap VPS to Run Docker Really Effective?
Network

Is Renting a Cheap VPS to Run Docker Really Effective?

July 2, 2026
How to get a free domain for 1 year from Gravatar
Network

How to get a free domain for 1 year from Gravatar

June 23, 2026
Cloud Infrastructure Resilience: Mitigating Advanced Layer 7 Vulnerabilities and Securing High-Throughput Database Handshakes
Network

Cloud Infrastructure Resilience: Mitigating Advanced Layer 7 Vulnerabilities and Securing High-Throughput Database Handshakes

June 20, 2026
Save image as Type contains malicious code: Remove immediately before losing money unfairly!
Network

Save image as Type contains malicious code: Remove immediately before losing money unfairly!

March 19, 2026
Instructions on how to register a .co.uk domain name for free for 1 year
Network

Instructions on how to register a .co.uk domain name for free for 1 year

March 12, 2026
How to Setup Paperclip AI: Create a Company for AI Agent
Network

How to Setup Paperclip AI: Create a Company for AI Agent

March 12, 2026
Next Post
Tips to find other people’s information on the Internet

Tips to find other people's information on the Internet

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted

Recent News

Instructions on how to get a certificate from Canva for free

Instructions on how to get a certificate from Canva for free

July 23, 2026
Microsoft confirms leaked Windows 11 is real

Microsoft confirms leaked Windows 11 is real

July 22, 2026
HeroSMS là gì? Cách thuê số điện thoại ảo nhận SMS OTP online không cần SIM

HeroSMS là gì? Cách thuê số điện thoại ảo nhận SMS OTP online không cần SIM

July 22, 2026
Little Sun Cloud Library: VTV’s audiobook application helps babies sleep well

Little Sun Cloud Library: VTV’s audiobook application helps babies sleep well

July 22, 2026
Instructions on how to get a certificate from Canva for free

Instructions on how to get a certificate from Canva for free

July 23, 2026
Microsoft confirms leaked Windows 11 is real

Microsoft confirms leaked Windows 11 is real

July 22, 2026
HeroSMS là gì? Cách thuê số điện thoại ảo nhận SMS OTP online không cần SIM

HeroSMS là gì? Cách thuê số điện thoại ảo nhận SMS OTP online không cần SIM

July 22, 2026
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

Instructions on how to get a certificate from Canva for free

Instructions on how to get a certificate from Canva for free

July 23, 2026
Microsoft confirms leaked Windows 11 is real

Microsoft confirms leaked Windows 11 is real

July 22, 2026
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply