{"id":20172,"date":"2023-10-18T19:13:11","date_gmt":"2023-10-19T02:13:11","guid":{"rendered":"https:\/\/portasftpserver.com\/?p=20172"},"modified":"2026-04-12T13:50:41","modified_gmt":"2026-04-12T20:50:41","slug":"how-to-use-fail2ban-with-porta-sftp-server","status":"publish","type":"post","link":"https:\/\/portasftpserver.com\/how-to-use-fail2ban-with-porta-sftp-server\/","title":{"rendered":"How To Use Fail2Ban With SFTP Server"},"content":{"rendered":"\n<p class=\"sera-block-paragraph\">Fail2Ban is a software that helps system administrators to block unwanted incoming connections from external hosts. This is triggered when events such as too many authentication failures happen to the SSH\/D server. in this post, let&#8217;s see how we can take advantage of this functionality that Fail2Ban has by invoking it after host denial from the Porta SFTP Server. This is important because blocking the incoming host at the firewall level increases security as it will not reach the application which prevents intrusion and brute force attack. <\/p>\n\n\n\n<p class=\"sera-block-paragraph\">To successfully follow this post, you must have the Porta SFTP Server installed on your machine, otherwise, read the blog <a rel=\"noreferrer noopener\" href=\"https:\/\/portasftpserver.com\/cross-platform-sftp-server\/\" data-type=\"link\" data-id=\"https:\/\/portasftpserver.com\/cross-platform-sftp-server\/\" target=\"_blank\">how to setup cross platform sftp server<\/a>.<\/p>\n\n\n\n<h2 class=\"sera-block-heading\">Installing <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/fail2ban\/fail2ban\" data-type=\"link\" data-id=\"https:\/\/github.com\/fail2ban\/fail2ban\" target=\"_blank\">Fail2Ban<\/a><\/h2>\n\n\n\n<p class=\"sera-block-paragraph\">Update the current Linux System<\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>sudo apt update<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E06C75\">sudo<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">apt<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">update<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Install the Fail2Ban<\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>sudo apt install fail2ban<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E06C75\">sudo<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">apt<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">install<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">fail2ban<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Check Fail2Ban Client Commands<\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>fail2ban-client<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E06C75\">fail2ban<\/span><span style=\"color: #56B6C2\">-<\/span><span style=\"color: #E06C75\">client<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<p class=\"sera-block-paragraph\">You should see similar to the following explains each commands.<\/p>\n\n\n\n<figure class=\"sera-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"958\" height=\"430\" src=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-9.png\" alt=\"\" class=\"sera-image-20248\" srcset=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-9.png 958w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-9-585x263.png 585w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-9-768x345.png 768w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-9-100x45.png 100w\" sizes=\"auto, (max-width: 958px) 100vw, 958px\" \/><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\"><em>Note. <\/em>Fail2Ban jail contains a combination of filters, actions, thresholds, etc&#8230;<\/p>\n\n\n\n<h2 class=\"sera-block-heading\">Configuring \/etc\/sudoers<\/h2>\n\n\n\n<p class=\"sera-block-paragraph\">In order to limit the Porta SFTP Server to communicating only with the Fail2Ban for the sake of banning external host IP addresses, we need to specify this under the \/etc\/sudoers file. To do so please follow these steps.<\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>sudo nano \/etc\/sudoers<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E06C75\">sudo<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">nano<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">etc<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">sudoers<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Then type the following at the bottom of the file<\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>myusername ALL=(ALL:ALL) NOPASSWD: \/bin\/fail2ban-client<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E5C07B\">myusername<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">ALL<\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\">(ALL:<\/span><span style=\"color: #E06C75\">ALL<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #E06C75\">NOPASSWD<\/span><span style=\"color: #ABB2BF\">: <\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">bin<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">fail2ban<\/span><span style=\"color: #56B6C2\">-<\/span><span style=\"color: #E06C75\">client<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"sera-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"951\" height=\"85\" src=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-11.png\" alt=\"\" class=\"sera-image-20261\" srcset=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-11.png 951w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-11-585x52.png 585w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-11-768x69.png 768w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-11-100x9.png 100w\" sizes=\"auto, (max-width: 951px) 100vw, 951px\" \/><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\"><em>Note. <\/em>Please change the &#8220;myusername&#8221; with you granted username (login username).<\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"sera-block-heading\">Configure and Run Fail2Ban<\/h2>\n\n\n\n<p class=\"sera-block-paragraph\">If you already have Fail2Ban running please stop it and do the following<\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>cd \/etc\/fail2ban<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E06C75\">cd<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">etc<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">fail2ban<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Edit the jail.local by putting the <strong>port<\/strong> number that Porta SFTP Server that is using and specify the <strong>bantime<\/strong><\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>sudo nano jail.local<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E06C75\">sudo<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">nano<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E5C07B\">jail<\/span><span style=\"color: #ABB2BF\">.<\/span><span style=\"color: #E5C07B\">local<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"sera-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"350\" src=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-12-1200x350.png\" alt=\"\" class=\"sera-image-20275\" srcset=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-12-1200x350.png 1200w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-12-585x170.png 585w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-12-768x224.png 768w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-12-100x29.png 100w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-12.png 1273w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\"><em>Note. <\/em>The [sshd] section is nearly towards the bottom and you have to scroll down further.<\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><strong>Finally <\/strong>run the Fail2Ban<\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>sudo systemctl start fail2ban<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E06C75\">sudo<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">systemctl<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">start<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">fail2ban<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<p class=\"sera-block-paragraph\">You can check the status by<\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>sudo systemctl status fail2ban<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E06C75\">sudo<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">systemctl<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">status<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">fail2ban<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"sera-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"271\" src=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-13-1200x271.png\" alt=\"\" class=\"sera-image-20285\" srcset=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-13-1200x271.png 1200w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-13-585x132.png 585w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-13-768x173.png 768w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-13-100x23.png 100w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-13.png 1275w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<h2 class=\"sera-block-heading\">Test With Porta SFTP Server<\/h2>\n\n\n\n<p class=\"sera-block-paragraph\">To test with Porta SFTP Server go to <strong>Manage<\/strong>-&gt;<strong>Bulk IP Address Filtering<\/strong>. From there specify the only allowed IP Address, <strong>tick <\/strong><em>enabled,<\/em> and <strong>tick <\/strong>the <em>Augment with Fail2Ban Intrusion Prevention<\/em>. Note that the latter is only applicable in Linux.<\/p>\n\n\n\n<figure class=\"sera-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"944\" height=\"752\" src=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/IPAddressFiltering.png\" alt=\"\" class=\"sera-image-20625\" srcset=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/IPAddressFiltering.png 944w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/IPAddressFiltering-585x466.png 585w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/IPAddressFiltering-768x612.png 768w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/IPAddressFiltering-100x80.png 100w\" sizes=\"auto, (max-width: 944px) 100vw, 944px\" \/><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\"><em>Note. <\/em>Spoiler, obviously, to test the banning functionality, you have to try to connect a different computer to the server that is not included in the whitelisted list.<\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><strong>Test Results<\/strong><\/p>\n\n\n\n<figure class=\"sera-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"942\" height=\"370\" src=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-16-e1699062608528.png\" alt=\"\" class=\"sera-image-20332\" srcset=\"https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-16-e1699062608528.png 942w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-16-e1699062608528-585x230.png 585w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-16-e1699062608528-768x302.png 768w, https:\/\/portasftpserver.com\/sera-uploads\/2023\/10\/image-16-e1699062608528-100x39.png 100w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\"><em>Note. <\/em>Currently, any IP Address that is not whitelisted will be banned immediately. The attempt failure that you will configure from Fail2ban does not apply yet. The only thing the Porta SFTP Server does is invoke the IP Ban functionality. The banned time will be based on your configuration in Fail2Ban.<\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><strong>Note.<\/strong> If you get the error\/warn message: <em>&#8220;WARN &#8211; Cannot run program &#8220;sudo&#8221;: error=13, Permission denied&#8221;<\/em>. Please execute the following command from the terminal:<\/p>\n\n\n\n<div class=\"sera-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>sudo chmod +x \/path\/to\/your\/Porta_SFTP_Server\/lib\/runtime\/lib\/jspawnhelper<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E06C75\">sudo<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">chmod<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">+<\/span><span style=\"color: #E06C75\">x<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">path<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">to<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">your<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">Porta_SFTP_Server<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">lib<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">runtime<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">lib<\/span><span style=\"color: #56B6C2\">\/<\/span><span style=\"color: #E06C75\">jspawnhelper<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"sera-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"sera-block-paragraph\">As you can see Fail2Ban is great software that can help you secure your SFTP Server. This post explains how the Porta SFTP Server can directly communicate with Fail2Ban and take advantage of its banning functionalities. To explore more about the Fail2Ban please visit its wiki documentation at https:\/\/github.com\/fail2ban\/fail2ban\/wiki.<\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fail2Ban is a software that helps system administrators to block unwanted incoming connections from external hosts. This is triggered when events such as too many authentication failures happen to the SSH\/D server. in this post, let&#8217;s see how we can take advantage of this functionality that Fail2Ban has by invoking it after host denial from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":20625,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189,1],"tags":[258,256,257,255,201],"class_list":["post-20172","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-free-software","category-programming-software","tag-fail2ban-in-linux","tag-fail2ban-with-sftp-server","tag-how-to-install-fail2ban","tag-how-to-use-fail2ban","tag-sftp-server-for-linux"],"_links":{"self":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts\/20172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/comments?post=20172"}],"version-history":[{"count":117,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts\/20172\/revisions"}],"predecessor-version":[{"id":25823,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts\/20172\/revisions\/25823"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/media\/20625"}],"wp:attachment":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/media?parent=20172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/categories?post=20172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/tags?post=20172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}