<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Featured Archives | The Curious Technoid</title>
	<atom:link href="https://thecurioustechnoid.com/category/featured/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecurioustechnoid.com/category/featured/</link>
	<description>technology made simple</description>
	<lastBuildDate>Tue, 07 Jul 2020 18:40:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://thecurioustechnoid.com/wp-content/uploads/2020/06/cropped-fav-1-32x32.png</url>
	<title>Featured Archives | The Curious Technoid</title>
	<link>https://thecurioustechnoid.com/category/featured/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Mojolicious (Part 1): Build Full App</title>
		<link>https://thecurioustechnoid.com/mojolicious-part1-homepage/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mojolicious-part1-homepage</link>
					<comments>https://thecurioustechnoid.com/mojolicious-part1-homepage/#respond</comments>
		
		<dc:creator><![CDATA[Rakshith Chengappa Mullengada]]></dc:creator>
		<pubDate>Sat, 27 Jun 2020 11:51:40 +0000</pubDate>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Perl / Mojolicious]]></category>
		<category><![CDATA[mojolicious]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[web framework]]></category>
		<guid isPermaLink="false">https://thecurioustechnoid.com/?p=349</guid>

					<description><![CDATA[<p>In the previous article we looked at how to install Mojolicious, build a hello world web app, test it and deploy the same in the instance. In the course of next few articles, we will look at building a mini project which covers session management, database connections, templates and layouts. Test Case Synopsis The test&#8230;</p>
<p>The post <a href="https://thecurioustechnoid.com/mojolicious-part1-homepage/">Mojolicious (Part 1): Build Full App</a> appeared first on <a href="https://thecurioustechnoid.com">The Curious Technoid</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In the <a aria-label="undefined (opens in a new tab)" href="/mojolicious-intro-hello-world/" target="_blank" rel="noreferrer noopener">previous article</a> we looked at how to install Mojolicious, build a hello world web app, test it and deploy the same in the instance. In the course of next few articles, we will look at building a mini project which covers <a href="/mojolicious-part-3-session-management/" target="_blank" aria-label="undefined (opens in a new tab)" rel="noreferrer noopener">session management</a>, <a href="/mojolicious-part-4-database-management/" target="_blank" aria-label="undefined (opens in a new tab)" rel="noreferrer noopener">database connections</a>, <a href="/mojolicious-part2-layouts-templates/" target="_blank" aria-label="undefined (opens in a new tab)" rel="noreferrer noopener">templates and layouts</a>.</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><a href="https://youtu.be/EdZNpI_t3Fw" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/WatchOnYoutubeImage.png" alt="" class="wp-image-78" width="217" height="87"/></a></figure></div>



<h2 class="wp-block-heading">Test Case Synopsis</h2>



<p>The test case that we have is to build a web application for testimonials. That&#8217;s the easiest one that I could think of to cover the topics I want to discuss. The web application will have the following features:</p>



<ul class="wp-block-list"><li><strong>Login Page:</strong> Which restricts website access to registered users</li><li><strong>Home Page: </strong>Main page for the registered users with a welcome message and website instructions</li><li><strong>Testimonial Page: </strong>Testimonial Page which displays all the testimonials from database entered by the users and option to save new testimonials in the database</li><li><strong>Log Out: </strong>To gracefully logout of the website</li></ul>



<p>We will also add a simple HTML template to the website which would cover the templates and layouts concept in Mojolicious.</p>



<p>Without further adieu, let&#8217;s begin building this project.</p>



<h2 class="wp-block-heading">Create full_app project</h2>



<p>In our previous tutorial on Mojolicious, we created &#8220;Hello World&#8221; web app with <em>lite_app</em>. This time we will build this project with <em>full_app</em>. To create a <em>full_app</em>, open the terminal and enter the below command:</p>



<pre class="wp-block-code"><code>mojo generate app myWebSite</code></pre>



<div class="wp-block-image"><figure class="aligncenter size-large"><img fetchpriority="high" decoding="async" width="758" height="857" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/mojo_generate_full-1.jpg" alt="" class="wp-image-359"/></figure></div>



<p>This will create a directory called <strong>myWebSite</strong> with the below folder structure:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="612" height="817" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/mojo_full_tree.jpg" alt="" class="wp-image-360"/></figure></div>



<p>Lets understand the below components from the above screenshot</p>



<ul class="wp-block-list"><li>lib</li><li>myWebSite.conf</li><li>public</li><li>script</li><li>t</li><li>templates</li></ul>



<h4 class="wp-block-heading">lib</h4>



<p>The library directory is probably the most crucial directory which holds all your programming code. Your Controller and Model logic goes here. The logic to handle any action on your webpage will be somewhere in this directory.</p>



<p>Your routes and page-actions are sent to the file <code>myWebSite/lib/myWebSite.pm</code> which then invokes the relevant Controller and Model to handle your requests.</p>



<h4 class="wp-block-heading">myWebSite.conf</h4>



<p>This is the master configuration file for your web app. You can add secret phrases for signed cookies, mention the number of workers that you want webservers to run, the port that your application should run on, database connection details, so on and so forth.</p>



<h4 class="wp-block-heading">public</h4>



<p>You can find all your static pages here. Along with the static pages, all publicly available components like your css, images or any other media goes into this directory.</p>



<h4 class="wp-block-heading">script</h4>



<p>Script to start your web site is present in this directory. You run you web app using the <code>script/myWebSite</code> file present in this directory.</p>



<h4 class="wp-block-heading">t</h4>



<p>Folder dedicated for your test scripts.</p>



<h4 class="wp-block-heading">templates</h4>



<p>Directory which holds the templates and layouts used by your web app.</p>



<p>I will not go in detail about the theory as you can always read more about it in the <a href="http://mojolicious.org/" target="_blank" aria-label="undefined (opens in a new tab)" rel="noreferrer noopener">official website</a> of Mojolicious. Let us proceed with our project.</p>



<p>Let&#8217;s go ahead and run this sample web app as it is, using the development web server morbo:</p>



<pre class="wp-block-code"><code>morbo myWebSite/script/myWebSite</code></pre>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="772" height="321" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/morbo_full_1.jpg" alt="" class="wp-image-362" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/morbo_full_1.jpg 772w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/morbo_full_1-768x319.jpg 768w" sizes="auto, (max-width: 772px) 100vw, 772px" /></figure></div>



<p>Since we don&#8217;t see any errors, let&#8217;s fire up the browser and check our page (I have <a href="/ssh-tunneling/" target="_blank" aria-label="undefined (opens in a new tab)" rel="noreferrer noopener">SSH Tunnel</a> enabled, so I can access the webpage with localhost IP and default port(3000):</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="724" height="242" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/mojo_full_samplepage.png" alt="" class="wp-image-363"/></figure>



<p>Our Website is running fine.</p>



<p>How did our website&#8217;s content get rendered ? Let us understand the flow of events. First, let me just remind you how the structure of your web application looks like:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="612" height="817" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/mojo_full_tree.jpg" alt="" class="wp-image-360"/></figure>



<p>Below diagram shows the flow of events from different files when you access your web page:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1543" height="903" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/MojoControlFlow-1.jpg" alt="" class="wp-image-354" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/MojoControlFlow-1.jpg 1543w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/MojoControlFlow-1-768x449.jpg 768w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/MojoControlFlow-1-1536x899.jpg 1536w" sizes="auto, (max-width: 1543px) 100vw, 1543px" /></figure></div>



<p>Whenever you access any web page built in mojolicious, the first file that gets called is the library file: <em>lib/myWebSite.pm</em>. The line <code>$r-&gt;get('/')-&gt;to('example#welcome');</code> in the file basically tells to go to the controller <em>Example.pm</em> and execute the <em>welcome</em> sub-routine. Controllers, as you can see in the above screenshot are stored in <em>lib/myWebSite/Controller</em>.</p>



<p>In the controller we see the below lines:</p>



<pre class="wp-block-code"><code># Render template "example/welcome.html.ep" with message
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!');</code></pre>



<p>This basically tells Mojolicious to set a value to the variable <code>$msg</code> and render the template. But which template ? We don&#8217;t see any template name mentioned in the controller, then which page is getting rendered?? Well, since no template is explicitly called Mojolicious will look for the template is the path similar to the controller path: <em>example/welcome</em>. In the above directory structure, we can see a template: <em>template/example/welcome.html.ep</em>, that&#8217;s what is getting rendered in the home page now. Ofcourse, you can explicitly mention the template name in the controller and it will exactly behave the same way. Just pass the template name like this:</p>



<pre class="wp-block-code"><code>  $self->render(msg => 'Welcome to the Mojolicious real-time web framework!',template => "example/welcome");</code></pre>



<p>I prefer explicitly mentioning the template names in my controller, to avoid any confusion.</p>



<p>Now that we know that our main page&#8217;s content is being displayed by <em>myWebSite/templates/example/welcome.html.ep</em> and the contents looks like this:</p>



<pre class="wp-block-code"><code>% layout 'default';
% title 'Welcome';
&lt;h2>&lt;%= $msg %>&lt;/h2>
&lt;p>
  This page was generated from the template "templates/example/welcome.html.ep"
  and the layout "templates/layouts/default.html.ep",
  &lt;%= link_to 'click here' => url_for %> to reload the page or
  &lt;%= link_to 'here' => '/index.html' %> to move forward to a static page.
&lt;/p></code></pre>



<p>We will change it to add our content:</p>



<pre class="wp-block-code"><code>% layout 'default';
% title 'Home Page';
&lt;h2>&lt;%= $msg %>&lt;/h2>
&lt;p> This is my personal site built with Mojolicious. You can provide testimonials using the link &lt;a href="#">here&lt;/a>. 
&lt;/p></code></pre>



<p>If you notice that the heading in the above html content is displayed by the variable <code>$msg</code>. This was set by our controller: <em>myWebSite/lib/myWebSite/Controller/Example.pm</em>. Let us open the controller file and change the below line:</p>



<pre class="wp-block-code"><code># Render template "example/welcome.html.ep" with message
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!');</code></pre>



<p>to</p>



<pre class="wp-block-code"><code># Render template "example/welcome.html.ep" with message
$self->render(msg => 'Welcome to My Personal Website!',template => "example/welcome");</code></pre>



<p>Not only did I change the heading, I also explicitly mentioned which template to render.</p>



<p>Lets run our web app with morbo:</p>



<pre class="wp-block-code"><code>morbo myWebSite/script/myWebSite</code></pre>



<p>Refresh our web browser:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="724" height="256" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/mojo_morbo_2.png" alt="" class="wp-image-364"/></figure>



<p>Working as expected. Before we wind up, lets just change the default controller and template files to our customized file names:</p>



<pre class="wp-block-code"><code>cp myWebSite/lib/myWebSite/Controller/Example.pm myWebSite/lib/myWebSite/Controller/CustomController.pm</code></pre>



<pre class="wp-block-code"><code>mkdir myWebSite/templates/myTemplates</code></pre>



<pre class="wp-block-code"><code>cp myWebSite/templates/example/welcome.html.ep myWebSite/templates/myTemplates/homepage.html.ep</code></pre>



<p><strong>New Controller Name : </strong><em>myWebSite/lib/myWebSite/Controller/CustomController.pm</em><br><strong>New Template Name : </strong><em>myWebSite/templates/myTemplates/homepage.html.ep</em></p>



<p>Open the new controller(CustomController.pm) and change the first line to reflect the new controller name, from:</p>



<pre class="wp-block-code"><code>package myWebSite::Controller::Example;</code></pre>



<p>to</p>



<pre class="wp-block-code"><code>package myWebSite::Controller::CustomController;</code></pre>



<p>Now change the below line in the same file to point to our newly created template: <em>myTemplates/homepage</em></p>



<pre class="wp-block-code"><code># Render template "example/welcome.html.ep" with message
$self->render(msg => 'Welcome to My Personal Website!',template => "example/welcome");</code></pre>



<p>to</p>



<pre class="wp-block-code"><code># Render template "myTemplates/homepage.html.ep" with message
$self->render(msg => 'Welcome to My Personal Website!',template => "myTemplates/homepage");</code></pre>



<p>Finally, open the main library file: <em>myWebSite/lib/myWebSite.pm</em> and change the below line to call our now custom controller rather than the default:</p>



<pre class="wp-block-code"><code>$r->get('/')->to('example#welcome');</code></pre>



<p>to</p>



<pre class="wp-block-code"><code>$r->get('/')->to('CustomController#welcome');</code></pre>



<p>Lets start our web app and refresh the browser:</p>



<pre class="wp-block-code"><code>morbo myWebSite/script/myWebSite</code></pre>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="686" height="265" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/mojo_full_page_final.jpg" alt="" class="wp-image-366"/></figure></div>



<p>You will not see any changes since we didn&#8217;t change the content. But we also didn&#8217;t see any errors that means we have achieved what we want.</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<p>We successfully created the home page of your website. In the <a href="/mojolicious-part2-layouts-templates/" target="_blank" aria-label="undefined (opens in a new tab)" rel="noreferrer noopener">next session</a>, we will learn about templates and layouts. We will try to add some color to our dull home page that we created in this article.</p>



<figure class="wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Mojolicious (Part 1): Build Full App (Home page)" width="640" height="360" src="https://www.youtube.com/embed/EdZNpI_t3Fw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>
<p>The post <a href="https://thecurioustechnoid.com/mojolicious-part1-homepage/">Mojolicious (Part 1): Build Full App</a> appeared first on <a href="https://thecurioustechnoid.com">The Curious Technoid</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thecurioustechnoid.com/mojolicious-part1-homepage/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SSH Tunneling (Port Forwarding) &#8211; a use case</title>
		<link>https://thecurioustechnoid.com/ssh-tunneling/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ssh-tunneling</link>
					<comments>https://thecurioustechnoid.com/ssh-tunneling/#respond</comments>
		
		<dc:creator><![CDATA[Rakshith Chengappa Mullengada]]></dc:creator>
		<pubDate>Sat, 20 Jun 2020 05:00:00 +0000</pubDate>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ssh port forwarding]]></category>
		<category><![CDATA[ssh tunnel]]></category>
		<category><![CDATA[ssh tunneling]]></category>
		<guid isPermaLink="false">https://thecurioustechnoid.com/?p=248</guid>

					<description><![CDATA[<p>SSH Tunneling creates an encrypted channel from your local Desktop to the remote server (and vice versa). Once the secured channel is established using SSH Tunnel, you can access the applications in the remote server without the need to open the firewall. This is especially helpful when ports are not open from your local Desktop&#8230;</p>
<p>The post <a href="https://thecurioustechnoid.com/ssh-tunneling/">SSH Tunneling (Port Forwarding) &#8211; a use case</a> appeared first on <a href="https://thecurioustechnoid.com">The Curious Technoid</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>SSH Tunneling creates an encrypted channel from your local Desktop to the remote server (and vice versa). Once the secured channel is established using SSH Tunnel, you can access the applications in the remote server without the need to open the firewall. This is especially helpful when ports are not open from your local Desktop to the remote server that you wish to access. This particularly comes in handy during development phase of your application or during troubleshooting. The only pre-requisite is that you need to have SSH access to that server. There are 3 types of SSH Tunneling: Local Port Forwarding, Remote Port Forwarding and Dynamic Port Forwarding. We will look at <strong>Local Port Forwarding</strong> in this article which is the most frequently used.</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><a href="https://youtu.be/KUdzXueyPZw" target="_blank" rel="noopener noreferrer"><img loading="lazy" decoding="async" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/WatchOnYoutubeImage.png" alt="" class="wp-image-78" width="217" height="87"/></a></figure></div>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Syntax</h2>



<p>Below is the syntax used to create a SSH Tunnel:</p>



<pre class="wp-block-code"><code>ssh -N -L LOCAL_PORT:HOST:HOST_PORT USER_NAME@REMOTE_SERVER</code></pre>



<ul class="wp-block-list"><li><code>-N</code>restricts you from inputting any command after the connection is established, this is preferred while using SSH Tunneling</li><li><code>-L</code> tells SSH that it’s <em>local port forwarding</em></li><li><code>LOCAL_PORT</code> The port we will use locally</li><li><code>HOST</code> The host address in the remote server. Usually localhost / 127.0.0.1 to access the application running in remote server.</li><li><code>HOST_PORT</code> The port number of the host address where the application is running</li><li><code>USER_NAME</code> User Name of the remote server</li><li><code>REMOTE_SERVER</code> Remote Server IP Address or hostname</li></ul>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Use Case: Connecting to remote database</h2>



<p>If you host your websites in one of the remote VPS servers, you would have stumbled upon the issue of connecting to the database from your local Desktop. I can access the database locally by opening the DB ports in firewall. But, what if I don&#8217;t like opening the DB ports ? The solution: <strong>SSH Tunneling</strong>. We can create a SSH Tunnel from our local Desktop to the VPS server using SSH. Port forward to the remote DB ports, after which we should be able to connect to the database in the remote server as if they are installed locally.</p>



<p>For the purpose of this demo, I have created a new server in <a href="https://m.do.co/c/a023a9d185b3" target="_blank" rel="noreferrer noopener">digital ocean</a> and have installed mariaDB database in it.</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading">Setup</h4>



<p><strong><u>Local Desktop:</u></strong><br><strong>Operating System:</strong> macOS Catalina<br><strong>Database Client:</strong> sequel Pro</p>



<p><span style="text-decoration: underline;"><strong>Remote Server:</strong></span><br data-rich-text-line-break="true" /><strong>Provider:</strong> Digital Ocean<br data-rich-text-line-break="true" /><strong>Operating System:</strong> Fedora 31 (Cloud Edition)<br data-rich-text-line-break="true" /><strong>Database Server:</strong> mariaDB</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>
</div></div>



<h4 class="wp-block-heading">Create SSH Tunnel</h4>



<p>First we will create the SSH Tunnel by running the below command in terminal:</p>



<pre class="wp-block-code"><code>ssh -N -L 2000:127.0.0.1:3306 demo@161.35.77.93 -i ~/.ssh/id_curioustechnoid</code></pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1316" height="564" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-tunnel-cmd.png" alt="" class="wp-image-254" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-tunnel-cmd.png 1316w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-tunnel-cmd-768x329.png 768w" sizes="auto, (max-width: 1316px) 100vw, 1316px" /></figure>



<ul class="wp-block-list"><li><code>2000</code> is the <strong>local port</strong> that we will use in the client</li><li><code>127.0.0.1 </code>is the <strong>Remote Server localhost</strong>. This is nothing but <em>localhost</em> in the remote server</li><li><code>3306 </code>is the <strong>Remote Server mariaDB Port</strong></li><li><code>demo</code> is the <strong>Remote SSH User Name</strong>.</li><li><code>161.35.77.93</code> This is the <strong>Remote Server IP Address</strong></li><li><code>~/.ssh/id_curioustechnoid</code> is the private <strong>SSH Key</strong> used to connect to server. Read more about <a href="/how-to-setup-ssh-keys/">SSH Keys here</a>.</li></ul>



<p>Change the values based on your setup. If all the options are provided correctly we should have an active SSH Tunnel created.</p>



<p>What the above command did is that it created a SSH Tunnel which port forwards any request on port 2000 to the remote server&#8217;s port 3306. In our case mariaDB is running in the default port 3306 in the remote server. In the above command, we are using SSH Keys to connect to the server. It&#8217;s strongly recommended to use <a href="/how-to-setup-ssh-keys/" target="_blank" rel="noreferrer noopener">SSH Keys</a> to connect to remote servers instead of username/password. <a href="/how-to-setup-ssh-keys/" target="_blank" rel="noreferrer noopener">Click here</a> to know more about <a href="/how-to-setup-ssh-keys/" target="_blank" rel="noreferrer noopener">SSH Keys</a>.</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading">Connect to database</h4>



<p>We now have encrypted connection established between local and remote server using the above SSH Tunnel command. Lets try to connect to the database in the remote server.</p>



<p>I will be using sequelPro database client and will connect to root database user. Enter the following details in connection section:</p>



<figure class="wp-block-table"><table><tbody><tr><td><strong>Host</strong></td><td>127.0.0.1</td><td><em>localhost</em></td></tr><tr><td><strong>Username</strong></td><td>root</td><td><em>Database User</em> <em>in the remote server</em></td></tr><tr><td><strong>Password</strong></td><td>*******</td><td><em>Database Password</em> <em>in the remote server</em></td></tr><tr><td><strong>Database</strong></td><td></td><td><em>Database you want to connect to.</em></td></tr><tr><td><strong>Port</strong></td><td>2000</td><td><em>Local port which while creating the SSH Tunnel</em></td></tr></tbody></table></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1191" height="779" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-tunnel-db-details.png" alt="" class="wp-image-256" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-tunnel-db-details.png 1191w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-tunnel-db-details-768x502.png 768w" sizes="auto, (max-width: 1191px) 100vw, 1191px" /><figcaption>Credential Details</figcaption></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1042" height="501" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-tunnel-db-connected.png" alt="" class="wp-image-257" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-tunnel-db-connected.png 1042w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-tunnel-db-connected-768x369.png 768w" sizes="auto, (max-width: 1042px) 100vw, 1042px" /><figcaption>Connection Established</figcaption></figure>



<p>We have successfully connected to the remote database using SSH Tunneling. You would have noticed that we are using localhost(127.0.0.1) and localport(2000) to connect to the database hosted in remote server. The practical usage of this concept in limitless.</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Hope this article helps you in using SSH Tunnels. Please feel free to share your experience or your issues in the comment section below. Happy to help!</p>



<figure class="wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="SSH Tunneling - A Use Case" width="640" height="360" src="https://www.youtube.com/embed/KUdzXueyPZw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p></p>
<p>The post <a href="https://thecurioustechnoid.com/ssh-tunneling/">SSH Tunneling (Port Forwarding) &#8211; a use case</a> appeared first on <a href="https://thecurioustechnoid.com">The Curious Technoid</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thecurioustechnoid.com/ssh-tunneling/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Secure your computer using fail2ban</title>
		<link>https://thecurioustechnoid.com/step-by-step-guide-to-configure-fail2ban/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=step-by-step-guide-to-configure-fail2ban</link>
					<comments>https://thecurioustechnoid.com/step-by-step-guide-to-configure-fail2ban/#respond</comments>
		
		<dc:creator><![CDATA[Rakshith Chengappa Mullengada]]></dc:creator>
		<pubDate>Fri, 12 Jun 2020 10:57:05 +0000</pubDate>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[linux]]></category>
		<guid isPermaLink="false">https://thecurioustechnoid.com/?p=143</guid>

					<description><![CDATA[<p>If you are not aware, fail2ban is a brute-force attack mitigation tool. This post will guide you to quickly install fail2ban with basic configuration. In this article I will be showing how to configure fail2ban for SSH brute-force attacks. Let&#8217;s cut to the chase and start installing fail2ban. For the purpose of this demonstration I&#8230;</p>
<p>The post <a href="https://thecurioustechnoid.com/step-by-step-guide-to-configure-fail2ban/">Secure your computer using fail2ban</a> appeared first on <a href="https://thecurioustechnoid.com">The Curious Technoid</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><a href="https://youtu.be/EcIJ9yj9Y2U" target="_blank" rel="noopener noreferrer"><img loading="lazy" decoding="async" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/WatchOnYoutubeImage.png" alt="" class="wp-image-78" width="217" height="87"/></a></figure></div>



<p>If you are not aware, fail2ban is a brute-force attack mitigation tool. This post will guide you to quickly install fail2ban with basic configuration. In this article I will be showing how to configure fail2ban for SSH brute-force attacks.</p>



<p>Let&#8217;s cut to the chase and start installing fail2ban.</p>



<p>For the purpose of this demonstration I shall be using Fedora 31. You should be able to find similar commands in your respective distros.</p>



<h2 class="wp-block-heading">Installation</h2>



<p>Installation is pretty straight forward similar to installing any other software in Linux. I will use the DNF package manager which is the default for Fedora now.</p>



<pre class="wp-block-code"><code>dnf install fail2ban -y</code></pre>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1249" height="699" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/install.png" alt="" class="wp-image-160" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/install.png 1249w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/install-768x430.png 768w" sizes="auto, (max-width: 1249px) 100vw, 1249px" /></figure></div>



<h2 class="wp-block-heading">Configuration</h2>



<p>In fail2ban, setup for a particular service like SSH is called as jail. Like any intruder being put into a jail, any intruder attempting to gain access to your server via SSH would be put inside &#8220;SSHD jail&#8221; and anyone trying to gain access via SFTP would be put inside &#8220;SFTP jail&#8221;. Controlling the parameters to be &#8220;eligible&#8221; to be put into these jails are handled by jail configuration file.</p>



<p>There are 2 configuration files in fail2ban:</p>



<ul class="wp-block-list"><li>/etc/fail2ban/jail.conf</li><li>/etc/fail2ban/fail2ban.conf</li></ul>



<p>It is recommended not to edit these files, but to create a copy of them with &#8216;.local&#8217; file extension. Once you have created the copy change the desired values in those files.</p>



<p><strong>fail2ban.conf </strong>file has the configuration to control fail2ban&#8217;s behaviour. For instance you can set the log level parameters here.<br><strong>jail.conf </strong>file is where you enable services (like ssh, sftp, apache) which you wish to monitor for intrusion. You also define criteria&#8217;s on when to block the IPs.</p>



<p>Below are the brief steps I usually follow to setup fail2ban to mitigate SSH brute-force attacks on my servers.</p>



<h3 class="wp-block-heading">1. <strong>Create &#8216;local&#8217; copies of config files:</strong></h3>



<pre class="wp-block-code"><code> cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
 cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local</code></pre>



<h3 class="wp-block-heading"><strong>2. Enable SSHD jail in jail.local file</strong></h3>



<p>First run the below command to check the active jails configured(should be none obviously):</p>



<p><code>fail2ban-client status</code></p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="885" height="401" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-status-nosetup.png" alt="" class="wp-image-161" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-status-nosetup.png 885w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-status-nosetup-768x348.png 768w" sizes="auto, (max-width: 885px) 100vw, 885px" /></figure></div>



<p>Since this is a fresh installation we can see that no jail has been configured.</p>



<p>Open the <em>jail.conf</em> using your favorite editor(obviously it&#8217;s vim!). Find the section where it says [sshd]. You might find 2 entries, 1 commented and the other uncommented, go to the uncommented entry which should look like this:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="886" height="585" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-default-jail.png" alt="" class="wp-image-162" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-default-jail.png 886w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/ssh-default-jail-768x507.png 768w" sizes="auto, (max-width: 886px) 100vw, 886px" /></figure></div>



<p>Change it to make it look something like this:</p>



<pre class="wp-block-code"><code>#
# SSH servers
#

&#91;sshd]

# To use more aggressive sshd modes set filter parameter "mode" in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
#mode   = normal
enabled = true
port    = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
maxretry = 3</code></pre>



<p>What did we exactly do here ?</p>



<ul class="wp-block-list"><li><strong>enabled</strong> : This enables the SSHD jail for fail2ban to keep monitoring the SSH connections to your server.</li><li><strong>maxretry</strong> : This defines how many incorrect password tries will you allow users trying to connect to your server via SSH. Beyond this, fail2ban will block them.</li></ul>



<h3 class="wp-block-heading"><strong>3. Additional Configuration</strong></h3>



<p><em>You can skip to step 4, if you want to ignore the below additional configurations but trust me you would want to know about these steps</em></p>



<p>I prefer to change few other parameters in <em>jail.local</em> when I setup fail2ban.</p>



<h5 class="wp-block-heading"><img loading="lazy" decoding="async" width="12" height="12" class="wp-image-184" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot.png" alt="" style="width: 12px;" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot.png 1024w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot-768x768.png 768w" sizes="auto, (max-width: 12px) 100vw, 12px" /><strong>  Ignoring IPs from being blocked</strong></h5>



<p>I have this habit of adding my own IPs to exception list so that I never get blocked by fail2ban. You might want to add your work IPs to this list so that you don&#8217;t get blocked while connecting from office in case you enter incorrect credentials multiple times. To add the the IPs that you want to exclude from monitoring, add them to the ignoreip parameter.</p>



<p>Uncomment and change the below line in <em>jail.local</em></p>



<p><code>#ignoreip = 127.0.0.1/8 ::1</code></p>



<p>to</p>



<p><code>ignoreip = 127.0.0.1/8 ::1 192.168.1.119</code></p>



<p>Assuming that my local IP that I want to exclude from blocking is 192.168.1.119, fail2ban will not &#8220;ban&#8221; this IP no matter how many times I enter incorrect credentials. You can add any number of IPs separated by space or comma.</p>



<h5 class="wp-block-heading"><img loading="lazy" decoding="async" width="12" height="12" class="wp-image-184" style="width: 12px;" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot.png" alt="" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot.png 1024w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot-768x768.png 768w" sizes="auto, (max-width: 12px) 100vw, 12px" />  <strong>Changing bantime and findtime</strong></h5>



<p>Fail2ban gives you the ability to customize certain things like When to Ban? How long to Ban?</p>



<p><strong>findtime</strong> parameter instructs fail2ban, within what duration should the &#8220;maxretry&#8221; value be checked. We had set the maxretry value(in sshd setup above) to 3, lets say we set findtime value to 60mins. So within 60mins if there are 3 incorrect attempts to login, then source IP gets added to ban list.</p>



<p> <strong>bantime</strong> parameter defines how long the IP should be banned, you may wish to ban the IP for a day, a week or a month. This parameter instructs fail2ban the same thing.</p>



<p>For example, lets say our maxretry value is 3 in SSHD configuration. You want to ban users if he enters incorrect password 3 times within a span of 10mins and block him from further attempting to try logging in for 3 days. You will change the value as below:</p>



<p><code>findtime = 10m</code></p>



<p><code>bantime = 76h</code></p>



<h5 class="wp-block-heading"><img loading="lazy" decoding="async" width="12" height="12" class="wp-image-184" style="width: 12px;" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot.png" alt="" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot.png 1024w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot-768x768.png 768w" sizes="auto, (max-width: 12px) 100vw, 12px" />  <strong>Enable logging via systemd journals</strong></h5>



<p>Fedora has a problem where unless logging is directed via systemd journald, it throws an error while starting fail2ban. To avoid this issue, you need to tell fail2ban to log via systemd journald by changing the below parameter:</p>



<p><code>backend = auto</code></p>



<p>to</p>



<p><code>backend = systemd</code></p>



<h5 class="wp-block-heading"><img loading="lazy" decoding="async" width="12" height="12" class="wp-image-184" style="width: 12px;" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot.png" alt="" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot.png 1024w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/blue-dot-768x768.png 768w" sizes="auto, (max-width: 12px) 100vw, 12px" />  Tell fail2ban to use firewalld to block the IPs</h5>



<p>I use firewalld as my firewall management tool so I tell fail2ban to use it to block the IPs by changing the below parameter</p>



<pre class="wp-block-code"><code># Default banning action (e.g. iptables, iptables-new,
# iptables-multiport, shorewall, etc) It is used to define
# action_* variables. Can be overridden globally or per
# section within jail.local file
banaction = iptables-multiport
banaction_allports = iptables-allports</code></pre>



<p>changed to:</p>



<pre class="wp-block-code"><code># Default banning action (e.g. iptables, iptables-new,
# iptables-multiport, shorewall, etc) It is used to define
# action_* variables. Can be overridden globally or per
# section within jail.local file
banaction = firewallcmd-ipset
banaction_allports = firewallcmd-ipset</code></pre>



<h2 class="wp-block-heading">Verify and start fail2ban</h2>



<p>Once we have all the changes done, we can verify our setup by running the command:</p>



<p><code>fail2ban-client -x start</code></p>



<p>fail2ban will tell us that set up in looking good.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="890" height="403" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-server-ready.png" alt="" class="wp-image-163" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-server-ready.png 890w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-server-ready-768x348.png 768w" sizes="auto, (max-width: 890px) 100vw, 890px" /></figure></div>



<p>Next step is to enable fail2ban so that it starts at boot time automatically. Then we proceed to start the fail2ban service to start monitoring all SSH connections.</p>



<p>Enable fail2ban so that it automatically starts at boot time</p>



<p><code>systemctl enable fail2ban.service</code></p>



<p>Start fail2ban service using the command:</p>



<p><code>systemctl start fail2ban.service</code></p>



<p>Make sure fail2ban is running fine</p>



<p><code>systemctl status fail2ban.service</code></p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1041" height="609" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-running-status-1.png" alt="" class="wp-image-165" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-running-status-1.png 1041w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-running-status-1-768x449.png 768w" sizes="auto, (max-width: 1041px) 100vw, 1041px" /></figure></div>



<p></p>



<p>Congratulations! We just enabled SSH jail to start monitoring all SSH connections to your server. You can check your ssh jail status by running the below command:</p>



<p><code>fail2ban-client status</code></p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="777" height="393" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-status.png" alt="" class="wp-image-166" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-status.png 777w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-status-768x388.png 768w" sizes="auto, (max-width: 777px) 100vw, 777px" /><figcaption>We can see 1 jail is configured, and the service enabled is SSH</figcaption></figure></div>



<p>You can check all the blocked IPs by running the command:</p>



<p><code>fail2ban-client status sshd</code></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="908" height="510" src="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-ssh-status.png" alt="" class="wp-image-167" srcset="https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-ssh-status.png 908w, https://thecurioustechnoid.com/wp-content/uploads/2020/06/fail2ban-ssh-status-768x431.png 768w" sizes="auto, (max-width: 908px) 100vw, 908px" /><figcaption>No IPs are blocked as it is a fresh installation</figcaption></figure>



<p>You can find the <a rel="noreferrer noopener" href="http://thecurioustechnoid.com/wp-content/uploads/misc/jail.local" target="_blank">jail.local</a> file with all the configuration discussed in this article <a rel="noreferrer noopener" href="http://thecurioustechnoid.com/wp-content/uploads/misc/jail.local" target="_blank">here</a>.</p>



<h2 class="wp-block-heading">Some useful commands to keep in mind</h2>



<ul class="wp-block-list"><li>Check all services monitored by fail2ban: <code>fail2ban-client status</code></li><li>Check the blocked IP List by ssh jail: <code>fail2ban-client status sshd</code></li><li>Remove blocked IPs: <code>fail2ban-client set sshd unbanip 192.168.143.191</code></li><li>Remove all blocked IPs: <code>fail2ban-client unban --all</code></li></ul>



<h2 class="wp-block-heading">Enable Debugging</h2>



<p>In case you stumble upon any issues, we can enable debugging to get more information.</p>



<p><strong>1. Open the file: /etc/fail2ban/fail2ban.local and change the below parameter</strong></p>



<p><code>loglevel = INFO</code></p>



<p>Change to</p>



<p><code>loglevel = DEBUG</code></p>



<p><strong>2. Restart the service</strong></p>



<p><code>systemctl restart fail2ban</code></p>



<p><strong>3. Monitor the debug messages</strong> by looking at the log file which be found at: /var/log/fail2ban.log</p>



<p><code>tail -f /var/log/fail2ban.log</code></p>



<p>If you wish to see fail2ban in action, I suggest you head to the <a rel="noreferrer noopener" href="https://youtu.be/EcIJ9yj9Y2U" target="_blank">video tutorial</a> that I created regarding fail2ban setup. You can drag the video to go directly to <strong>06:32</strong> to see fail2ban in action skipping all the setup which we already discussed in this article. </p>



<figure class="wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Secure your computer using fail2ban" width="640" height="360" src="https://www.youtube.com/embed/EcIJ9yj9Y2U?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>
<p>The post <a href="https://thecurioustechnoid.com/step-by-step-guide-to-configure-fail2ban/">Secure your computer using fail2ban</a> appeared first on <a href="https://thecurioustechnoid.com">The Curious Technoid</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thecurioustechnoid.com/step-by-step-guide-to-configure-fail2ban/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Page Caching using Disk: Enhanced 
Database Caching 26/48 queries in 0.006 seconds using Disk

Served from: thecurioustechnoid.com @ 2026-04-19 07:18:24 by W3 Total Cache
-->