{"id":32,"date":"2010-01-29T21:57:44","date_gmt":"2010-01-30T03:57:44","guid":{"rendered":"http:\/\/www.linuxpoweruser.com\/?p=32"},"modified":"2010-01-29T21:57:44","modified_gmt":"2010-01-30T03:57:44","slug":"ssh-tunneling-aka-poor-mans-vpn","status":"publish","type":"post","link":"https:\/\/www.linuxpoweruser.com\/?p=32","title":{"rendered":"SSH Tunnelling (aka Poor Man&#8217;s VPN)"},"content":{"rendered":"<p>Tunnelling of TCP traffic can be performed from the ssh command on Linux or with Putty on Windows, and can be thought of as a poor man&#8217;s VPN.\u00a0 A VPN is a virtual private network, or a method of using a public network such as the internet to\u00a0 securely transmit data via an encrypted &#8220;tunnel&#8221;.<\/p>\n<p>VNC is a method of gaining access to a remote GUI on Linux and Windows machines.\u00a0 VNC is typically considered insecure and not recommended for use on the open internet.\u00a0 With an SSH tunnel, this doesn&#8217;t have to be an issue, as ssh provides security to an otherwise insecure protocol.<\/p>\n<p>Here is an example of how to use VNC over an SSH tunnel:<\/p>\n<p>Start VNC server on a Linux host ssh server to only listen to Loopback interface:<br \/>\n<code><br \/>\nvncserver :1 -localhost<br \/>\n<\/code><br \/>\nOn client machine, start ssh with the following command line:<br \/>\n<code><br \/>\nssh -L 5901:localhost:5901 &lt;server ip&gt; [-l &lt;login&gt;]<br \/>\n<\/code><br \/>\nThe to access VNC via the SSH tunnel, use the following command on the client machine:<br \/>\n<code><br \/>\nvncviewer localhost:1<br \/>\n<\/code><br \/>\nWhat happens?<\/p>\n<p>The ssh process on the client sets up a TCP port redirection on the loopback interface of port 5901, to the loopback interface on the server machine on TCP port 5901. \u00a0The vncviewer command connects to the the redirected port on the local loopback interface, which then gets directed over the tunnel to the server machine&#8217;s loopback on port 5901, where the vncserver is listening.<\/p>\n<p>This will allow vnc protocol to be securely tunnelled across the SSH connection.<\/p>\n<p>The previous examples showed connecting to services running on the ssh server itself.\u00a0 Its also possible to use the SSH server to redirect traffic to other machines on the network behind it.<\/p>\n<p>Sometimes we might have to access a Windows Machine behind an a linux SSH server that is connected to the internet (such as linux system performing firewalling for a home network).  We can use SSH tunnelling to connect to Windows Remote Desktop as well. (I know this is a linux blog, but most of us out there still have to deal with Windows from time to time)<\/p>\n<p>The following example assumes the following network layout:<\/p>\n<p>Client PC &#8211;&gt; Internet&#8211;&gt;SSH Server on Firewall&#8211;&gt;Private Network&#8211;&gt; Windows XP<br \/>\n(188.18.199.11)\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (192.168.0.11)<br \/>\n(ssh server can be behind firewall as long as its accessible from Internet)<\/p>\n<p>1. Make sure Windows XP host is running RDP<\/p>\n<p>2. On client PC, start SSH with tunnelling as follows: 4000:192.168.0.11:3389<\/p>\n<p>On Putty this tunnel definition looks like this (click add after completing the boxes):<\/p>\n<p><a href=\"http:\/\/www.linuxpoweruser.com\/wp-content\/uploads\/2010\/01\/snapshot2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-35\" title=\"Windows Putty Tunnel Definition Screenshot\" src=\"http:\/\/www.linuxpoweruser.com\/wp-content\/uploads\/2010\/01\/snapshot2.png\" alt=\"\" width=\"1031\" height=\"808\" \/><\/a><\/p>\n<p>Which is exactly like the ssh command on Linux:<br \/>\n<code><br \/>\nssh -L 4000:192.168.0.11:3389 &lt;server&gt; -l &lt;userid&gt;<br \/>\n<\/code><br \/>\nTo connect to the RDP service on the internal Windows XP system, from a client Windows system connected to the internet via the ssh connection:<\/p>\n<p>Use Remote Desktop Connection application that comes with XP, but use this as the address to connect to:<\/p>\n<p><a href=\"http:\/\/www.linuxpoweruser.com\/wp-content\/uploads\/2010\/01\/snapshot31.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-34\" title=\"RDP client connecting to localhost:4000\" src=\"http:\/\/www.linuxpoweruser.com\/wp-content\/uploads\/2010\/01\/snapshot31.png\" alt=\"\" width=\"1031\" height=\"808\" \/><\/a><\/p>\n<p>Like the previous example, this causes the program to connect to port # 4000 on the local loopback interface, which then is redirected to the 192.168.0.11 machine on port number 3389 at the other end of the ssh tunnel. \u00a0Port # 4000 is used to avoid conflicting with port #3389 on the client as it could have its own RDP server running.<\/p>\n<p>Any TCP based communications can be tunnelled this way over ssh, creating a secure connection for any unsecure protocol. This is also a mechanism for bypassing firewall rules.\u00a0 As long as the SSH server traffic is allowed (TCP port 22).\u00a0 It can be used to gain access to other ports that might not be allowed by a local firewall, simply by using a remote ssh server as a proxy for other traffic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tunnelling of TCP traffic can be performed from the ssh command on Linux or with Putty on Windows, and can be thought of as a poor man&#8217;s VPN.\u00a0 A VPN is a virtual private network, or a method of using a public network such as the internet to\u00a0 securely transmit data via an encrypted &#8220;tunnel&#8221;. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,10],"tags":[49,57,62,66,68,72],"_links":{"self":[{"href":"https:\/\/www.linuxpoweruser.com\/index.php?rest_route=\/wp\/v2\/posts\/32"}],"collection":[{"href":"https:\/\/www.linuxpoweruser.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxpoweruser.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxpoweruser.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxpoweruser.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=32"}],"version-history":[{"count":0,"href":"https:\/\/www.linuxpoweruser.com\/index.php?rest_route=\/wp\/v2\/posts\/32\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.linuxpoweruser.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxpoweruser.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxpoweruser.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}