<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://dev1galaxy.org/extern.php?action=feed&amp;tid=7933&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / [HowTo] Protect from SHH brute force attacks with fail2ban]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=7933</link>
		<description><![CDATA[The most recent posts in [HowTo] Protect from SHH brute force attacks with fail2ban.]]></description>
		<lastBuildDate>Sat, 25 Apr 2026 02:06:37 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[[HowTo] Protect from SHH brute force attacks with fail2ban]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=63399#p63399</link>
			<description><![CDATA[<p>An SSH brute force attack is a hacking technique where attackers use automated tools to systematically try thousands of username and password combinations to gain unauthorized access to a remote server via the Secure Shell (SSH) protocol.</p><p>To be fair this is not a definitive protection but another countermeasure to reduce drastically the risks from such attacks when using public IPs.</p><p># As a complementary measure you should NOT allow ssh root login using password but using ssh key in worst case escenario, to do that change the settings for sshd:</p><div class="codebox"><pre><code>sudo nano /etc/ssh/sshd_config</code></pre></div><p># Uncomment the #PermitRootLogin line like:<br /><span class="bbc">PermitRootLogin prohibit-password</span></p><p># Install packages:</p><div class="codebox"><pre><code>sudo apt install -y fail2ban lnav</code></pre></div><p># Verify connection attemps</p><div class="codebox"><pre><code>sudo lnav /var/log/auth.log</code></pre></div><p># You will see very often lines like:<br /><span class="bbc">&lt;date&gt; - &lt;time&gt; &lt;hostname&gt; sshd[pid]: Failed password for root from xxx.xxx.xxx.xxx port xxxx ssh2</span> &lt;--- Brute force attack</p><p># and also when you connect you will see a line like this:<br /><span class="bbc">&lt;date&gt; - &lt;time&gt; &lt;hostname&gt; sshd[pid]: Accepted publikey for &lt;youruser&gt; from &lt;your.isp.public.ip&gt; port xxxxx ssh2: EDxxxx SHAxxx</span> &lt;--- This is you, will whitelist this IP.</p><p># Press q to exit</p><p># Create Local Configuration to preserve settings during updates.</p><div class="codebox"><pre><code>sudo nano /etc/fail2ban/jail.local</code></pre></div><p># Configure SSH Protection, we will use 3 attemps to block earlier than 5 attemps and for 3 hours but later you can increase the bantime if you notice the same IP addresses repeating again and again:<br /><span class="bbc">[DEFAULT]<br /># Whitelist your own IP address (space-separated)<br />ignoreip = 127.0.0.1/8 ::1 &lt;your.isp.public.ip&gt;</span></p><p><span class="bbc">[sshd]<br />enabled = true<br />maxretry = 3<br />bantime = 3h<br />findtime = 10m</span>&#160; &#160;</p><p># Restart fail2ban service</p><div class="codebox"><pre><code>sudo service fail2ban restart</code></pre></div><p># Verify ssh jail status</p><div class="codebox"><pre><code>sudo fail2ban-client status sshd</code></pre></div><p>&#160; </p><p># You will see something like:</p><div class="codebox"><pre><code>Status for the jail: sshd
|- Filter
|  |- Currently failed:	1
|  |- Total failed:	5
|  `- File list:	/var/log/auth.log
`- Actions
   |- Currently banned:	6
   |- Total banned:	6
   `- Banned IP list:	2.57.122.189 2.57.122.192 45.148.10.147 45.148.10.151 45.148.10.157 92.118.39.236</code></pre></div><p>&#160; &#160;<br /># Now if you verify connection attemps again<br /><span class="bbc">sudo lnav /var/log/auth.log</span></p><p>You will notice the attemps wont repeat from the same IP since the moment fail2ban was restarted, keep it running and eventually they will realize is not worthy to keep trying or they will run out of public IPS or you can also increase the time if the same IP address keep showing up.</p><p>To add an extra layer of protection you can also enable 2FA with oathtool to make ssh ask for 6 digits code before you can enter any password, that way the attack never even begins since the client gets disconnected and banned when doens&#039;t provide a valid 6 digits code to begin with the login attemp, link to guide below.</p><p><a href="https://dev1galaxy.org/viewtopic.php?id=7657" rel="nofollow">[HowTo] 2FA TOTPs for SSH without google-authenticator.</a></p>]]></description>
			<author><![CDATA[dummy@example.com (joser)]]></author>
			<pubDate>Sat, 25 Apr 2026 02:06:37 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=63399#p63399</guid>
		</item>
	</channel>
</rss>
