From d33c43030d46afd56f62a10880bb27f8add2ec30 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 24 Jul 2020 02:52:35 +0200 Subject: [PATCH] Omit the use of `sudo` when running as root. --- ddos-mitigator.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ddos-mitigator.sh b/ddos-mitigator.sh index 80ade70..cbe0051 100755 --- a/ddos-mitigator.sh +++ b/ddos-mitigator.sh @@ -370,7 +370,12 @@ sudo -k # one of them. while read -r addr ; do echo "Banning ${addr} ..." - sudo fail2ban-client set apache-badbots banip "${addr}" + if [[ $(id -un) == "root" ]] ; then + # Don't use sudo when we're running as root. + fail2ban-client set apache-auth banip "${addr}" + else + sudo fail2ban-client set apache-auth banip "${addr}" + fi done < "${banlist}" echo -e "${green}All done!${reset}"