LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-26-2024, 04:21 AM   #1
Jason.nix
Member
 
Registered: Feb 2023
Posts: 562

Rep: Reputation: 10
Post What part of the Fail2Ban configuration is wrong?


Hello,
The SSH part of Fail2ban is as follows:
Code:
[sshd]
enabled = true
port    = 22
logpath = /var/log/ssh-fail2ban.log
backend = %(sshd_backend)s
maxretry  = 2
findtime  = 10
bantime   = 4w
I connected to the host and entered the wrong SSH password a few times, but I was not blocked. Why?

Thank you.
 
Old 02-26-2024, 06:19 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by Jason.nix View Post
I connected to the host and entered the wrong SSH password a few times, but I was not blocked. Why?
Because your Fail2Ban config doesn't make sense.
Quote:
Originally Posted by Jason.nix View Post
Code:
logpath = /var/log/ssh-fail2ban.log
That's supposed to be the path to the log containing the authentication errors, not where F2B will log its activity.
 
1 members found this post helpful.
Old 02-26-2024, 07:42 AM   #3
bitfuzzy
Member
 
Registered: Nov 2003
Location: NY
Distribution: slackware
Posts: 464

Rep: Reputation: 133Reputation: 133
Try

Code:
logpath = %(sshd_log)s
 
Old 02-26-2024, 07:48 AM   #4
bitfuzzy
Member
 
Registered: Nov 2003
Location: NY
Distribution: slackware
Posts: 464

Rep: Reputation: 133Reputation: 133
IMO you might want to consider allowing connections to SSH from only trusted IP's and BLOCK access to all others
Though this works best where connecting clients are using Static IP's.

It's not meant to replace fail2ban's ssh policy, but to act as your first line of defense.
 
Old 02-26-2024, 10:53 AM   #5
Jason.nix
Member
 
Registered: Feb 2023
Posts: 562

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by bitfuzzy View Post
Try

Code:
logpath = %(sshd_log)s
Hello,
Thank you so much for your reply.
When I use logpath = %(sshd_log)s, then when I restart the Fail2Ban service I get the following error message:
Quote:
Failed during configuration: Have not found any log file for sshd jail.
 
Old 02-26-2024, 02:03 PM   #6
bitfuzzy
Member
 
Registered: Nov 2003
Location: NY
Distribution: slackware
Posts: 464

Rep: Reputation: 133Reputation: 133
Check /etc/fail2ban/

You should have a file named paths-common.conf

Make a copy of the file and name it paths-common.local

open the file and search for sshd

If you don't find sshd_log add:
Code:
sshd_log = %(syslog_authpriv)s
If you don't find sshd_backend also add:
Code:
sshd_backend = %(default_backend)s
Restart fail2ban and see if that helps

Ken
 
1 members found this post helpful.
Old 02-26-2024, 11:45 PM   #7
Jason.nix
Member
 
Registered: Feb 2023
Posts: 562

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by bitfuzzy View Post
Check /etc/fail2ban/

You should have a file named paths-common.conf

Make a copy of the file and name it paths-common.local

open the file and search for sshd

If you don't find sshd_log add:
Code:
sshd_log = %(syslog_authpriv)s
If you don't find sshd_backend also add:
Code:
sshd_backend = %(default_backend)s
Restart fail2ban and see if that helps

Ken
Hello,
Thank you so much for your reply.
After this I restarted the Fail2Ban service and got the following errors:
Code:
[715]: ERROR   Failed during configuration: Have not found any log file for sshd jail
[715]: ERROR   Async configuration of server failed
In the jail.local file, I changed the backend value from %(sshd_backend)s to systemd and the problem was solved.

Last edited by Jason.nix; 02-27-2024 at 12:04 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Need help with fail2ban configuration specs. Debian 10 xmx Linux - Server 3 02-01-2024 10:52 AM
LXer: How to Install Fail2ban on Ubuntu 20.04 with Configuration LXer Syndicated Linux News 0 07-23-2021 06:28 AM
Use bash script in Fail2Ban Configuration dannyvdberg Linux - Software 10 03-15-2018 05:49 PM
[SOLVED] fail2ban does not ban, maybe my regex is wrong? JeanC Linux - Server 2 03-17-2011 10:01 AM
LXer: Wells Grants in Part IBM's Motion to Limit SCO's Claims! In *Large* Part. LXer Syndicated Linux News 0 06-28-2006 09:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration