<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts on Esad Cetiner</title><link>https://ecetiner.com/posts/</link><description>Recent content in Posts on Esad Cetiner</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>© 2026 Esad Cetiner</copyright><lastBuildDate>Thu, 12 Jan 2023 18:11:16 +0000</lastBuildDate><atom:link href="https://ecetiner.com/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>Free dynamic DNS with Cloudflare</title><link>https://ecetiner.com/linux/fast-dynamic-dns-with-cloudflare/</link><pubDate>Thu, 12 Jan 2023 18:11:16 +0000</pubDate><guid>https://ecetiner.com/linux/fast-dynamic-dns-with-cloudflare/</guid><description><description>&lt;p&gt;Do you want to host a website at home, or run your own personal cloud with Nextcloud? Chances are, you have a dynamic IP address assigned from your ISP. A common issue with running services at home is having to frequently update your DNS records whenever your IP address changes, luckily with Dynamic DNS (DDNS) this can be automated. Cloudflare offers a powerful API that allows us to automate various tasks such as updating what IP address our DNS records point to, a &lt;a href="https://github.com/K0p1-Git/cloudflare-ddns-updater" target="_blank" rel="noreferrer"&gt;github user&lt;/a&gt; has written a shell script that lets us take advantage of Cloudflare&amp;rsquo;s API without having to write any code!&lt;/p&gt;
&lt;h2 class="relative group"&gt;Prerequisites
&lt;div id="prerequisites" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#prerequisites" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;You must own a domain name.&lt;/li&gt;
&lt;li&gt;You must either have your DNS Nameservers pointed to Cloudflare or use Cloudflare as a domain registrar.&lt;/li&gt;
&lt;li&gt;You must have a Linux Server that&amp;rsquo;s running at home.&lt;/li&gt;
&lt;li&gt;Linux Fundamentals&lt;/li&gt;
&lt;li&gt;Networking Fundamentals.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class="relative group"&gt;Downloading the script
&lt;div id="downloading-the-script" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#downloading-the-script" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;To download the script, first make sure you have git installed and then git clone the script.&lt;/p&gt;
&lt;h3 class="relative group"&gt;Ubuntu / Debian
&lt;div id="ubuntu--debian" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#ubuntu--debian" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo apt install git&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 class="relative group"&gt;RHEL / Cent OS
&lt;div id="rhel--cent-os" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#rhel--cent-os" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo yum install git&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 class="relative group"&gt;Cloning the repository
&lt;div id="cloning-the-repository" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#cloning-the-repository" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git clone https://github.com/K0p1-Git/cloudflare-ddns-updater&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;That&amp;rsquo;s it for now, we have to create an API token to use this script.&lt;/p&gt;
&lt;h2 class="relative group"&gt;Getting our API token and Zone ID
&lt;div id="getting-our-api-token-and-zone-id" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#getting-our-api-token-and-zone-id" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;To get your API token go to &lt;a href="https://dash.cloudflare.com" target="_blank" rel="noreferrer"&gt;https://dash.cloudflare.com&lt;/a&gt;, log in, and then click your domain name, in my case this is ecetiner.com. You&amp;rsquo;ll then want to look for &amp;ldquo;Get your API Token&amp;rdquo; at the very bottom right of your screen, I&amp;rsquo;ve included a screenshot as it can be hard to find for some people. Right above &amp;ldquo;Get your API Token&amp;rdquo; You&amp;rsquo;ll see your Zone ID, copy and save it as we&amp;rsquo;ll need it for the script to work.&lt;/p&gt;
&lt;figure&gt;&lt;img
class="my-0 rounded-md"
loading="lazy"
decoding="async"
fetchpriority="low"
alt="An image showing where to get your API token."
src="https://ecetiner.com/wp-content/uploads/get-api-token-ddns.webp"
&gt;&lt;/figure&gt;
&lt;p&gt;Next under API Token you want to click &amp;ldquo;Create Token&amp;rdquo; then under &amp;ldquo;Edit DNS Zone&amp;rdquo; click &amp;ldquo;Use Template&amp;rdquo;. Your token&amp;rsquo;s permissions should look like mine.&lt;/p&gt;
&lt;figure&gt;&lt;img
class="my-0 rounded-md"
loading="lazy"
decoding="async"
fetchpriority="low"
alt="An Image showing what permissions to use when creating a token. The only permission needed is DNS being set to edit."
src="https://ecetiner.com/wp-content/uploads/create-api-token-ddns.webp"
&gt;&lt;/figure&gt;
&lt;p&gt;After that you&amp;rsquo;ll want to click &amp;ldquo;Continue to summary&amp;rdquo; then &amp;ldquo;Create Token&amp;rdquo;. Your token will be displayed and a &lt;code&gt;curl&lt;/code&gt; command will be provided which lets you test the API token. Make sure you keep the token somewhere safe and don&amp;rsquo;t publish it on the internet as it can negatively impact your security. If your token is missing or was compromised, then you can &amp;ldquo;roll&amp;rdquo; the token which will generate a new one and invalidate the old one.&lt;/p&gt;
&lt;h2 class="relative group"&gt;Configuring the script
&lt;div id="configuring-the-script" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#configuring-the-script" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;Go back to your server and cd into cloudflare-ddns-updater.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cd cloudflare-ddns-updater/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Open the file cloudflare-template.sh with a text editor, nano is a good beginner friendly text editor.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;nano cloudflare-template.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once you open the file you&amp;rsquo;ll be shown some lines that you&amp;rsquo;ll need to be configure, enter whatever value is relevant for your use case within the quotation marks then save and exit. The table below will guide you on how to fill it out.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setting&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;auth_email&lt;/td&gt;
&lt;td&gt;Put the email address that is used to log into Cloudflare.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;auth_method&lt;/td&gt;
&lt;td&gt;Set this value to token.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;auth_key&lt;/td&gt;
&lt;td&gt;You put the API token that we generated earlier here, Go back to “Getting our API token” if you do not have a API token.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;zone_identifier&lt;/td&gt;
&lt;td&gt;Put your Zone ID here, go back to “Getting our API token” if you don’t know what yours is.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;record-name&lt;/td&gt;
&lt;td&gt;Add your DNS record name here, subdomain.example.com or example.com go here.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ttl&lt;/td&gt;
&lt;td&gt;How long (In seconds) a change in your DNS will take effect, set this to 60 so your DNS record can update quickly.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;proxy&lt;/td&gt;
&lt;td&gt;If you want to proxy your website through Cloudflare set this to true, Otherwise set it to false.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 class="relative group"&gt;Testing the script
&lt;div id="testing-the-script" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#testing-the-script" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;To test the script, update the DNS record you want DDNS for and set it to an invalid IP address (For example 1.1.1.1). Make sure you wait a few minutes for the change to propagate. Check with dig to see if your DNS is invalid.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;dig a example.com&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.18.1-1ubuntu1.2-Ubuntu &amp;lt;&amp;lt;&amp;gt;&amp;gt; a example.com
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; global options: +cmd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; Got answer:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 22899
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; OPT PSEUDOSECTION:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;; EDNS: version: 0, flags:; udp: 65494
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; QUESTION SECTION:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;example.com. IN A
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; ANSWER SECTION:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;example.com. 3600 IN A 93.184.216.34
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; Query time: 320 msec
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; WHEN: Fri Jan 13 04:26:46 AEDT 2023
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;;; MSG SIZE rcvd: 56&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once your DNS record has propigated, run the script, wait a few minutes then check again with dig. Your IP address should be your home IP address now.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo bash cloudflare-template.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 class="relative group"&gt;Create a cronjob to auto run the script
&lt;div id="create-a-cronjob-to-auto-run-the-script" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#create-a-cronjob-to-auto-run-the-script" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;Now that we have a functioning script, we need to setup a cronjob so it runs automatically every minute. After all, nobody wants to have to run the script manually everytime something breaks!&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;crontab -e&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Copy paste the following and replace /path/to/script with the location to your script.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;*/1 * * * * bash /path/to/script/cloudflare-template.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;That&amp;rsquo;s all there is to it, you&amp;rsquo;ve now setup DDNS with Cloudflare and your DNS records will be automatically updated as your IP address changes!&lt;/p&gt;</description></description></item><item><title>Ultimate guide to securing SSH</title><link>https://ecetiner.com/linux/ultimate-guide-to-securing-ssh/</link><pubDate>Wed, 14 Sep 2022 22:00:00 +0000</pubDate><guid>https://ecetiner.com/linux/ultimate-guide-to-securing-ssh/</guid><description><description>&lt;p&gt;SSH is a popular tool for remotely managing Servers and networking equipment, it&amp;rsquo;s;s installed and enabled by default on every single Linux/BSD-based server. Since SSH is so widely used in many environments, it has become an obvious and easy target for many threat actors. If something goes wrong with SSH, things can go wrong quickly, making it an especially valuable target.&lt;/p&gt;
&lt;h2 class="relative group"&gt;Required Knowledge
&lt;div id="required-knowledge" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#required-knowledge" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Linux Fundamentals&lt;/li&gt;
&lt;li&gt;Networking fundamentals&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 class="relative group"&gt;Testing and backups
&lt;div id="testing-and-backups" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#testing-and-backups" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;Before making any configuration changes to your Server, you should first test these changes in a testing environment. If all goes well, backup your production server and then apply your changes.&lt;/p&gt;
&lt;h2 class="relative group"&gt;Patch, Patch, Patch
&lt;div id="patch-patch-patch" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#patch-patch-patch" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;This really should go without saying, but make sure you always install the latest security updates for any kind of software installed on your server. Patching protects your system against known security vulnerabilities. You should set up automatic patching using tools like unattended-upgrades to help stay on top on all of the latest security updates. I will write a future blog post that will cover unattended-upgrades.&lt;/p&gt;
&lt;h2 class="relative group"&gt;Firewalling SSH
&lt;div id="firewalling-ssh" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#firewalling-ssh" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;Firewalls work by filtering IP addresses, ports, and protocols, they can be a lightweight, simple and yet effective tool for preventing attacks. Most saine firewalls will block all incoming traffic by default, so you&amp;rsquo;ll need to create allow rules to allow the traffic you need. So for example if you have a HTTP server then you need to open port 80 and 443 in your firewall, port 25 for an email server, etc. The trick here is to not just open port 22 for SSH, but only allow a handful of IP addresses to access port 22 and block everybody else. Just by doing this alone, your already making it extremely difficult for anybody to even talk to your SSH server. Good luck trying to break in if you can&amp;rsquo;t even talk to SSH.&lt;/p&gt;
&lt;h3 class="relative group"&gt;Installing UFW
&lt;div id="installing-ufw" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#installing-ufw" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;I&amp;rsquo;ll be using UFW firewall as an example since it&amp;rsquo;s easy to use, but feel free to use other firewalls.&lt;/p&gt;
&lt;h4 class="relative group"&gt;Ubuntu / Debain
&lt;div id="ubuntu--debain" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#ubuntu--debain" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo apt update
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo apt install ufw&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4 class="relative group"&gt;RHEL / Cent OS
&lt;div id="rhel--cent-os" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#rhel--cent-os" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo dnf install ufw&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 class="relative group"&gt;Creating UFW firewall rules
&lt;div id="creating-ufw-firewall-rules" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#creating-ufw-firewall-rules" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;UFW already denies all incoming connections by default, so all you need to do is create your allow rules for SSH.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; To allow a range or group of IP addresses, add a CIDR notation at the end of an IP address i.e: 10.0.0.1/24&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo ufw allow in from your-ip to any port 22 proto tcp&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;To allow all IP addresses to access port 22, use this command:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; This leave port 22 wide open to the internet and provides no security for SSH&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo ufw allow in from any to any port 22 proto tcp&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;To allow access to other services to your server, say for example your running NGINX you&amp;rsquo;ll need to create the following allow rules so others can access your website:&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo ufw allow in from any to any port 80 proto tcp
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo ufw allow in from any to any port 443&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once your done, double check you created all the rules you need with &lt;code&gt;sudo ufw status&lt;/code&gt;&lt;/p&gt;
&lt;h3 class="relative group"&gt;Enabling UFW
&lt;div id="enabling-ufw" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#enabling-ufw" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;Once you have added all of the firewall rules you need, enable UFW with the &lt;code&gt;sudo ufw enable&lt;/code&gt; command.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;WARNING:&lt;/strong&gt; Make sure you created an allow rule for SSH before enabling the firewall to avoid locking youself out.&lt;/p&gt;
&lt;h2 class="relative group"&gt;Secure Authentication
&lt;div id="secure-authentication" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#secure-authentication" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;Weak passwords and authentication is by far one of the biggest reason any kind of server gets compromised, this isn&amp;rsquo;t helped by the fact strong and unique passwords are difficult to remember. This can be solved by using SSH keys, they&amp;rsquo;re easy to use, next to impossible to guess, and you can even login without a password! The only relatively small problem you&amp;rsquo;ll have to worry about is someone stealing your SSH key, but you can password protect the key to buy you time to change it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Using passwords for SSH is fine as long as you have a secure password, but SSH keys are easier to use.&lt;/p&gt;
&lt;h3 class="relative group"&gt;Generating SSH Keys
&lt;div id="generating-ssh-keys" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#generating-ssh-keys" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;To generate an SSH key, just run the &lt;code&gt;ssh-keygen -t ed25519&lt;/code&gt; command, you can optionally protect it with a password if you wish.&lt;/p&gt;
&lt;h3 class="relative group"&gt;Uploading your public key to the SSH Server
&lt;div id="uploading-your-public-key-to-the-ssh-server" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#uploading-your-public-key-to-the-ssh-server" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;Once you&amp;rsquo;ve generated your SSH key you&amp;rsquo;ll need to upload it to the server, this process is slightly different depending on what your computer&amp;rsquo;s operating system is.&lt;/p&gt;
&lt;h4 class="relative group"&gt;Linux
&lt;div id="linux" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#linux" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;
&lt;p&gt;On Linux this can be done with one command:&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ssh-copy-id username@your-server-ip&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4 class="relative group"&gt;Windows Clients
&lt;div id="windows-clients" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#windows-clients" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;
&lt;p&gt;Copying SSH keys from a Windows computer is a bit tricker than Linux. First, we&amp;rsquo;ll have to manually create the SSH folder with the correct permissions on the server and then upload our key.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mkdir -p ~/.ssh
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;chmod 0700 ~/.ssh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once you have created the folder and assigned it the correct permissions, use the SCP command to upload the key.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;scp $env:USERPROFILE/.ssh/id_ed25519.pub username@your-server-ip:~/.ssh/authorized_keys&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 class="relative group"&gt;Logging into your Server with a SSH key
&lt;div id="logging-into-your-server-with-a-ssh-key" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#logging-into-your-server-with-a-ssh-key" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;From now on you should be able to log into SSH without a password (If you didn&amp;rsquo;t set one) as long as you have your SSH key stored in your home directory&amp;rsquo;s .ssh folder.&lt;/p&gt;
&lt;h3 class="relative group"&gt;Disabling Password Authentication
&lt;div id="disabling-password-authentication" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#disabling-password-authentication" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;Once all user accounts use SSH keys, disable password authentication to take advantage of the security improvements that come with SSH Keys. Create a drop-in file for SSH called 10-harden.conf under /etc/ssh/sshd_config.d/.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo mkdir -p /etc/ssh/sshd_config.d/ /etc/ssh/ssh_config.d/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo nano /etc/ssh/sshd_config.d/10-harden.conf
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo ln -s /etc/ssh/sshd_config.d/10-harden.conf /etc/ssh/ssh_config.d/10-harden.conf&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then add the following:&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;PasswordAuthentication no
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;PubkeyAuthentication yes&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 class="relative group"&gt;Restart SSH
&lt;div id="restart-ssh" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#restart-ssh" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;To apply your changes, restart SSH:&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo sshd -t &amp;amp;&amp;amp; systemctl restart ssh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 class="relative group"&gt;Brute Force Protection
&lt;div id="brute-force-protection" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#brute-force-protection" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;A brute force attack is essentially an attack where somebody tries to guess your password, you can stop these attacks using a tool like &lt;a href="https://www.crowdsec.net" target="_blank" rel="noreferrer"&gt;CrowdSec&lt;/a&gt; is a log analysis tool that protects against SSH brute force attacks by banning the offending IP address, it can detect other attacks such as &lt;a href="https://app.crowdsec.net/hub/author/crowdsecurity/collections/http-dos" target="_blank" rel="noreferrer"&gt;DDoS&lt;/a&gt;, &lt;a href="https://app.crowdsec.net/hub/author/crowdsecurity/collections/base-http-scenarios" target="_blank" rel="noreferrer"&gt;XSS, SQLi, web based scanners&lt;/a&gt; and &lt;a href="https://app.crowdsec.net/hub/author/crowdsecurity/scenarios/ssh-cve-2024-6387" target="_blank" rel="noreferrer"&gt;SSH exploitation attempts&lt;/a&gt; but for now I&amp;rsquo;ll be covering SSH.&lt;/p&gt;
&lt;h3 class="relative group"&gt;Installing CrowdSec
&lt;div id="installing-crowdsec" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#installing-crowdsec" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;CrowdSec is primarily made up of 2 components, the Security Engine (detects attacks) and the Remediation Component (blocks attacks). CrowdSec is currently not included in any official repositories, so we must first install the official CrowdSec repository, then we&amp;rsquo;ll install the CrowdSec Security Engine and Remediation Component. The Security Engine and Remediation Component is smart enough to auto-configure itself to detect and block attacks so we don&amp;rsquo;t have to do anything else. In most cases all you need to do is just run two commands.&lt;/p&gt;
&lt;h4 class="relative group"&gt;Debian / Ubuntu
&lt;div id="debian--ubuntu" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#debian--ubuntu" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | sudo bash
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo apt install crowdsec crowdsec-firewall-bouncer-iptables&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4 class="relative group"&gt;RHEL / Cent OS
&lt;div id="rhel--cent-os-1" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#rhel--cent-os-1" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.rpm.sh | sudo bash
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo yum install crowdsec crowdsec-firewall-bouncer-iptables&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4 class="relative group"&gt;Impossible Travel and Successful brute force attacks (Optional)
&lt;div id="impossible-travel-and-successful-brute-force-attacks-optional" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#impossible-travel-and-successful-brute-force-attacks-optional" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;
&lt;p&gt;In addition to brute force attacks, CrowdSec can detect &lt;a href="https://www.crowdsec.net/blog/detect-suspicious-ip-behavior-impossible-travel" target="_blank" rel="noreferrer"&gt;&amp;ldquo;Impossible Travel&amp;rdquo;&lt;/a&gt; and &lt;a href="https://www.crowdsec.net/blog/detecting-successful-ssh-brute-force" target="_blank" rel="noreferrer"&gt;Successful brute force attacks&lt;/a&gt; on SSH. The installation method is similar to manually configuring SSH for CrowdSec. However, you can shoot yourself in the foot if you don&amp;rsquo;t know what you&amp;rsquo;re doing. I won&amp;rsquo;t cover how to set it up here, but if you&amp;rsquo;re interested you can see how to do so &lt;a href="https://app.crowdsec.net/hub/author/crowdsecurity/collections/sshd-impossible-travel" target="_blank" rel="noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 class="relative group"&gt;Reduce attack surface
&lt;div id="reduce-attack-surface" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#reduce-attack-surface" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Attack_surface" target="_blank" rel="noreferrer"&gt;Attack Surface&lt;/a&gt; is essentially all of the ways you can be hacked. Generally, the more complex a system is, the more features it has, the more likely it is to have a security vulnerability and therefore experience a security incident. It&amp;rsquo;s impossible to have no attack surface, but you can reduce it to ensure there are no unnecessary risks. SSH already has a pretty small attack surface, but we can further reduce it by disabling insecure and unnecessary features.&lt;/p&gt;
&lt;h3 class="relative group"&gt;Disable unnecessary features
&lt;div id="disable-unnecessary-features" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#disable-unnecessary-features" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;Create an SSH drop-in file (If you haven&amp;rsquo;t already).&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo mkdir -p /etc/ssh/sshd_config.d/ /etc/ssh/ssh_config.d/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo nano /etc/ssh/sshd_config.d/10-harden.conf
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo ln -s /etc/ssh/sshd_config.d/10-harden.conf /etc/ssh/ssh_config.d/10-harden.conf&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then add the following settings.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Some of these suggestions may break certain functionality within SSH, take a look at the table below to see what changes you may want to make then test it to make sure nothing is broken!&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Configuration&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;X11 Forwarding&lt;/td&gt;
&lt;td&gt;Enable/disable GUI over SSH with X11 Server.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GatewayPorts&lt;/td&gt;
&lt;td&gt;Used for port forwarding over SSH&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PermitTunnel&lt;/td&gt;
&lt;td&gt;Used for port forwarding over SSH&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AllowTcpForwarding&lt;/td&gt;
&lt;td&gt;Used to port forward TCP ports over SSH. If you are using a database GUI program or similar to access an database on the server, then setting this to no may break it. Try setting this to local first before leaving it to a default value (yes).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AllowStreamLocalForwarding&lt;/td&gt;
&lt;td&gt;Used for port forwarding over SSH&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Protocol&lt;/td&gt;
&lt;td&gt;There are two versions of SSH, V1, and V2. V2 is considered more secure and V1 is not supported. If your SSH client/server doesn&amp;rsquo;t support SSHv2 then you really should update it.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PermitEmptyPasswords&lt;/td&gt;
&lt;td&gt;If set to no, this will disable SSH login for user accounts without a password.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LoginGraceTime&lt;/td&gt;
&lt;td&gt;How long to wait for an SSH client to log in before disconnecting them.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MaxAuthTries&lt;/td&gt;
&lt;td&gt;How many failed login attempts are allowed before being disconnected, this can help slow down brute force attacks by acting as an rate-limit.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;StrictModes&lt;/td&gt;
&lt;td&gt;If set to yes, an SSH user won&amp;rsquo;t log in an user if their SSH folder has insecure permissions (i.e rwx 777)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Compression&lt;/td&gt;
&lt;td&gt;Enable/disable compression of SSH messages.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 class="relative group"&gt;Limiting SSH Users
&lt;div id="limiting-ssh-users" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#limiting-ssh-users" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;You can also limit the users and user groups that can login via SSH. This is useful to prevent SSH logins from an account that shouldn&amp;rsquo;t be accessed over SSH, typically caused by a misconfiguration.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;AllowUsers exampleuser exampleuser1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;AllowGroups examplegroup examplegroup1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 class="relative group"&gt;Disabling Root Login
&lt;div id="disabling-root-login" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#disabling-root-login" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;
&lt;p&gt;Sometimes people might suggest disabling root login for SSH and to use a sudo user to login instead, but this actually doesn&amp;rsquo;t have any security benefit in many cases. If you are the only one that&amp;rsquo;s maintaining the server then using the root account is fine. If multiple people are logging into the server then you should use sudo account so you can have better control over user accounts and permissions.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;PermitRootLogin no&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 class="relative group"&gt;Restart SSH
&lt;div id="restart-ssh-1" class="anchor"&gt;&lt;/div&gt;
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
&lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#restart-ssh-1" aria-label="Anchor"&gt;#&lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;
&lt;p&gt;Restart SSH to apply your changes.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo sshd -t &amp;amp;&amp;amp; systemctl restart ssh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</description></description></item></channel></rss>