I'm trying to configure the /etc/fail2ban/jail.local config with an bash script. I was thinking to use sed and regular expression to change the sections I need.
sed -i "s/^bantime = 600/bantime = $1/" /etc/fail2ban/jail.local
sed -i "s/^destemail = root@localhost/destemail = $2/" /etc/fail2ban/jail.local
sed -i "s/^action = %(action_)s/action = %(action_mwl)s/" /etc/fail2ban/jail.local
As you can see for bantime, destemail and action I'm able to do so. Only if it matches the exactly. I could be that the bantime, or the destemail is changed, then the script won't work. What can i use to make after the = sign flexable. For example if bantime is not 600 but 700 it will also change using the bash script.
Also there is an section to configure SSH and SSHD:
[ssh]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 6
[dropbear]
enabled = false
port = ssh
filter = sshd
logpath = /var/log/dropbear
maxretry = 6
[ssh-ddos]
enabled = false
port = ssh
filter = sshd-ddos
logpath = /var/log/auth.log
maxretry = 6
I also want to specify the port I use for SSH or enable SSHD with sed and regular expression. But as you can see when i match on enabled I will change all jails or if I match on port I will change all ports in the config. This is not what I want.
Can anybody assist me with an way to configur Fail2Ban with an script and a flexible way?
Many thanks, Raoul