<?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>ssh port forwarding Archives | The Curious Technoid</title>
	<atom:link href="https://thecurioustechnoid.com/tag/ssh-port-forwarding/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecurioustechnoid.com/tag/ssh-port-forwarding/</link>
	<description>technology made simple</description>
	<lastBuildDate>Sun, 28 Jun 2020 17:28:11 +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>ssh port forwarding Archives | The Curious Technoid</title>
	<link>https://thecurioustechnoid.com/tag/ssh-port-forwarding/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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 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 fetchpriority="high" 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="(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 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="(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>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Page Caching using Disk: Enhanced 
Database Caching 3/40 queries in 0.006 seconds using Disk

Served from: thecurioustechnoid.com @ 2026-06-19 01:25:54 by W3 Total Cache
-->