{"id":4868,"date":"2024-11-11T16:20:24","date_gmt":"2024-11-11T08:20:24","guid":{"rendered":"https:\/\/www.ookangzheng.com\/?p=4868"},"modified":"2024-11-11T16:21:34","modified_gmt":"2024-11-11T08:21:34","slug":"fail2ban-startup-fail-on-debian","status":"publish","type":"post","link":"https:\/\/www.ookangzheng.com\/fail2ban-startup-fail-on-debian\/","title":{"rendered":"Fail2ban startup fail on Debian"},"content":{"rendered":"\n

Error message<\/h2>\n\n\n\n

The key message: Failed during configuration: Have not found any log file for sshd jail<\/code><\/p>\n\n\n\n

\u279c ~ \/usr\/bin\/fail2ban-server -xf start\n2024-11-11 02:12:02,637 fail2ban.configreader   [1255228]: WARNING 'allowipv6' not defined in 'Definition'. Using default one: 'auto'\n2024-11-11 02:12:02,647 fail2ban                [1255228]: ERROR   Failed during configuration: Have not found any log file for sshd jail\n2024-11-11 02:12:02,651 fail2ban                [1255228]: ERROR   Async configuration of server failed<\/code><\/pre>\n\n\n\n

Solution<\/h2>\n\n\n\n

Edit \/etc\/fail2ban\/jail.local<\/p>\n\n\n\n

On [Default] add backend=systemd<\/code> will fix the issue.<\/p>\n\n\n\n

nano \/etc\/fail2ban\/jail.local\n\n[DEFAULT]\nbackend=systemd\nignoreip = 127.0.0.1\nbantime = 86400\nmaxretry = 5\nfindtime = 1800\n\n[ssh-iptables]\nenabled = true\nfilter = sshd\naction = iptables[name=SSH, port=ssh, protocol=tcp]\nlogpath = \/var\/log\/auth.log\nmaxretry = 5\nfindtime = 3600\nbantime = 31536000<\/code><\/pre>\n\n\n\n

Reference<\/p>\n\n\n\n

    \n
  1. https:\/\/github.com\/fail2ban\/fail2ban\/issues\/3292#issuecomment-1142579029<\/a><\/li>\n<\/ol>\n\n\n\n

    Photo by Brusk Dede<\/a> on Unsplash<\/a><\/p>\n\n\n\n

    Script to install fail2ban<\/h3>\n\n\n\n
    #!\/bin\/bash\n\nCHECK_OS(){\n\tif [[ -f \/etc\/redhat-release ]];then\n\t\trelease=\"centos\"\n\telif cat \/etc\/issue | grep -q -E -i \"debian\";then\n\t\trelease=\"debian\"\n\telif cat \/etc\/issue | grep -q -E -i \"ubuntu\";then\n\t\trelease=\"ubuntu\"\n\telif cat \/etc\/issue | grep -q -E -i \"centos|red hat|redhat\";then\n\t\trelease=\"centos\"\n\telif cat \/proc\/version | grep -q -E -i \"debian\";then\n\t\trelease=\"debian\"\n\telif cat \/proc\/version | grep -q -E -i \"ubuntu\";then\n\t\trelease=\"ubuntu\"\n\telif cat \/proc\/version | grep -q -E -i \"centos|red hat|redhat\";then\n\t\trelease=\"centos\"\n\tfi\n}\n\nGET_SETTING_FAIL2BAN_INFO(){\n\tread -p \"\u5141\u8bb8SSH\u767b\u9646\u5931\u8d25\u6b21\u6570,\u9ed8\u8ba410:\" BLOCKING_THRESHOLD\n\tif [[ ${BLOCKING_THRESHOLD} = \"\" ]];then\n\t\tBLOCKING_THRESHOLD='10'\n\tfi\n\n\tread -p \"SSH\u767b\u9646\u5931\u8d25\u6b21\u6570\u8d85\u8fc7${BLOCKING_THRESHOLD}\u6b21\u65f6,\u5c01\u7981\u65f6\u957f(h),\u9ed8\u8ba48760:\" BLOCKING_TIME_H\n\tif [[ ${BLOCKING_TIME_H} = \"\" ]];then\n\t\tBLOCKING_TIME_H='8760'\n\tfi\n\n\tBLOCKING_TIME_S=$(expr ${BLOCKING_TIME_H} \\* 3600)\n}\n\nINSTALL_FAIL2BAN(){\n\tif [ ! -e \/etc\/fail2ban\/jail.local ];then\n\t\tCHECK_OS\n\t\tcase \"${release}\" in\n\t\t\tcentos)\n\t\t\t\tGET_SETTING_FAIL2BAN_INFO\n\t\t\t\tyum -y install epel-release\n\t\t\t\tyum -y install fail2ban;;\n\t\t\tdebian|ubuntu)\n\t\t\t\tGET_SETTING_FAIL2BAN_INFO\n\t\t\t\tapt-get -y install fail2ban;;\n\t\t\t*)\n\t\t\t\techo \"\u8bf7\u4f7f\u7528CentOS,Debian,Ubuntu\u7cfb\u7edf.\";;\n\t\tesac\n\telse\n\t\techo \"fail2ban\u5df2\u7ecf\u5b89\u88c5\u4e86.\";exit\n\tfi\n}\n\nREMOVE_FAIL2BAN(){\n\tif [ -e \/etc\/fail2ban\/jail.local ];then\n\t\tCHECK_OS\n\t\tcase \"${release}\" in\n\t\t\tcentos)\n\t\t\t\tservice fail2ban stop\n\t\t\t\tyum -y remove fail2ban\n\t\t\t\trm -rf \/etc\/fail2ban\/jail.local;;\n\t\t\tdebian|ubuntu)\n\t\t\t\tservice fail2ban stop\n\t\t\t\tapt-get -y remove fail2ban\n\t\t\t\trm -rf \/etc\/fail2ban\/jail.local;;\n\t\tesac\n\telse\n\t\techo \"fail2ban\u5c1a\u672a\u5b89\u88c5.\";exit\n\tfi\n}\n\nSETTING_FAIL2BAN(){\n\tCHECK_OS\n\tcase \"${release}\" in\n\t\tcentos)\n\t\t\techo \"[DEFAULT]\nignoreip = 127.0.0.1\nbantime = 86400\nmaxretry = 3\nfindtime = 1800\n\n[ssh-iptables]\nenabled = true\nfilter = sshd\naction = iptables[name=SSH, port=ssh, protocol=tcp]\nlogpath = \/var\/log\/secure\nmaxretry = ${BLOCKING_THRESHOLD}\nfindtime = 3600\nbantime = ${BLOCKING_TIME_S}\" > \/etc\/fail2ban\/jail.local\n\t\t\tif [ -e \/usr\/bin\/systemctl ];then\n\t\t\t\tsystemctl restart fail2ban\n\t\t\t\tsystemctl enable fail2ban\n\t\t\t\tsystemctl restart sshd\n\t\t\telse\n\t\t\t\tservice fail2ban restart\n\t\t\t\tchkconfig fail2ban on\n\t\t\t\tservice ssh restart\n\t\t\tfi;;\n\t\tdebian|ubuntu)\n\t\t\techo \"[DEFAULT]\nignoreip = 127.0.0.1\nbantime = 86400\nmaxretry = ${BLOCKING_THRESHOLD}\nfindtime = 1800\n\n[ssh-iptables]\nenabled = true\nfilter = sshd\naction = iptables[name=SSH, port=ssh, protocol=tcp]\nlogpath = \/var\/log\/auth.log\nmaxretry = ${BLOCKING_THRESHOLD}\nfindtime = 3600\nbantime = ${BLOCKING_TIME_S}\" > \/etc\/fail2ban\/jail.local\n\t\t\tservice fail2ban restart\n\t\t\tservice ssh restart;;\n\tesac\n}\n\nVIEW_RUN_LOG(){\n\tCHECK_OS\n\tcase \"${release}\" in\n\t\tcentos)\n\t\t\ttail -f \/var\/log\/secure;;\n\t\tdebian|ubuntu)\n\t\t\ttail -f \/var\/log\/auth.log;;\n\tesac\n}\n\ncase \"${1}\" in\n\tinstall)\n\t\tINSTALL_FAIL2BAN\n\t\tSETTING_FAIL2BAN;;\n\tuninstall)\n\t\tREMOVE_FAIL2BAN;;\n\tstatus)\n\t\techo -e \"\\033[41;37m\u3010\u8fdb\u7a0b\u3011\\033[0m\";ps aux | grep fail2ban\n\t\techo;echo -e \"\\033[41;37m\u3010\u72b6\u6001\u3011\\033[0m\";fail2ban-client ping\n\t\techo;echo -e \"\\033[41;37m\u3010Service\u3011\\033[0m\";service fail2ban status;;\n\tblocklist|bl)\n\t\tif [ -e \/etc\/fail2ban\/jail.local ];then\n\t\t\tfail2ban-client status ssh-iptables\n\t\telse\n\t\t\techo \"fail2ban\u5c1a\u672a\u5b89\u88c5.\";exit\n\t\tfi;;\n\tunlock|ul)\n\t\tif [ -e \/etc\/fail2ban\/jail.local ];then\n\t\t\tif [[ \"${2}\" = \"\" ]];then\n\t\t\t\tread -p \"\u8bf7\u8f93\u5165\u9700\u8981\u89e3\u5c01\u7684IP:\" UNLOCK_IP\n\t\t\t\tif [[ ${UNLOCK_IP} = \"\" ]];then\n\t\t\t\t\techo \"\u4e0d\u5141\u8bb8\u7a7a\u503c,\u8bf7\u91cd\u8bd5.\";exit\n\t\t\t\telse\n\t\t\t\t\tfail2ban-client set ssh-iptables unbanip ${UNLOCK_IP}\n\t\t\t\tfi\n\t\t\telse\n\t\t\t\tfail2ban-client set ssh-iptables unbanip ${2}\n\t\t\tfi\n\t\telse\n\t\t\techo \"fail2ban\u5c1a\u672a\u5b89\u88c5.\";exit\n\t\tfi;;\n\tmore)\n\t\techo \"\u3010\u53c2\u8003\u6587\u7ae0\u3011\nhttps://www.fail2ban.org\nhttps:\/\/linux.cn\/article-5067-1.html\n\n\u3010\u66f4\u591a\u547d\u4ee4\u3011\nfail2ban-client -h\";;\n\trunlog)\n\t\tVIEW_RUN_LOG;;\n\tstart)\n\t\tservice fail2ban start;;\n\tstop)\n\t\tservice fail2ban stop;;\n\trestart)\n\t\tservice fail2ban restart;;\n\t*)\n\t\techo \"bash fail2ban.sh {install|uninstall|runlog|more}\"\n\t\techo \"bash fail2ban.sh {start|stop|restart|status}\"\n\t\techo \"bash fail2ban.sh {blocklist|unlock}\";;\nesac\n\n#END<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

    Error message The key message: Failed during configuration: Have not found any log file for sshd jail Solution Edit \/etc\/fail2ban\/jail.local…<\/p>\n","protected":false},"author":1,"featured_media":4871,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,32],"tags":[74,82,79],"class_list":["post-4868","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-technology","tag-linux","tag-server","tag-vps"],"_links":{"self":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/4868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/comments?post=4868"}],"version-history":[{"count":2,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/4868\/revisions"}],"predecessor-version":[{"id":4872,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/posts\/4868\/revisions\/4872"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/media\/4871"}],"wp:attachment":[{"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/media?parent=4868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/categories?post=4868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ookangzheng.com\/wp-json\/wp\/v2\/tags?post=4868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}