{"id":124,"date":"2024-01-30T20:47:37","date_gmt":"2024-01-31T01:47:37","guid":{"rendered":"https:\/\/coding101.xyz\/?p=124"},"modified":"2024-01-30T20:48:41","modified_gmt":"2024-01-31T01:48:41","slug":"putty-reverse-ssh","status":"publish","type":"post","link":"https:\/\/coding101.xyz\/?p=124","title":{"rendered":"Putty Reverse SSH"},"content":{"rendered":"\n<p>This shows how to configure reverse SSH having a linux machine on the cloud, exposing a port on that one that is forwarded on your home machine at a specified port. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p>The settings are two:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>one setting on the machine, allowing remote SSH to bind to all IP addresses when reverse is triggered, otherwise will only bind to loopback address (security feature)<\/li>\n\n\n\n<li>one setting on local machine, running windows and Putty to trigger the connection. <\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Remote Machine<\/h2>\n\n\n\n<p>On the remote machine assume you run Linux with sshd. Go to the settings file \/etc\/ssh\/sshd_config and look for the setting called GatewayPorts, which can have three values<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>off &#8211; for tunnel SSH only binds to localhost, that means the reverse connection port is only accessible from the remote machine itself<\/li>\n\n\n\n<li>on &#8211; forces bind to all IP addresses associated to the machine, which allows access from remote machines<\/li>\n\n\n\n<li>clientspecified &#8211; the client indicates to which IP address to bind for this particular setting<\/li>\n<\/ul>\n\n\n\n<p>Do not forget to restart sshd after those changes are done<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart ssh<\/code><\/pre>\n\n\n\n<p>OK now on the machine, fire up Putty and first setup the connection as SSH connection and specify the remote machine address; the port is 22 usually. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"455\" height=\"208\" src=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image.png\" alt=\"\" class=\"wp-image-125\" srcset=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image.png 455w, https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-300x137.png 300w\" sizes=\"auto, (max-width: 455px) 100vw, 455px\" \/><\/figure>\n\n\n\n<p>OK and now proceed to SSH \/ Tunnels<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"192\" height=\"396\" src=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-1.png\" alt=\"\" class=\"wp-image-126\" srcset=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-1.png 192w, https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-1-145x300.png 145w\" sizes=\"auto, (max-width: 192px) 100vw, 192px\" \/><\/figure>\n\n\n\n<p>There, those are the settings:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"419\" height=\"423\" src=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-2.png\" alt=\"\" class=\"wp-image-127\" srcset=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-2.png 419w, https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-2-297x300.png 297w, https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-2-150x150.png 150w\" sizes=\"auto, (max-width: 419px) 100vw, 419px\" \/><\/figure>\n\n\n\n<p>The entry is already configured, however <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>select &#8220;remote ports do the same&#8221; although it is not used here<\/li>\n\n\n\n<li>Source port is the port where you connect on the remote machine<\/li>\n\n\n\n<li>Destination is localhost:port with the port on the local machine. <\/li>\n\n\n\n<li>Select <strong>Remote<\/strong> radio button (the R after 4 in the connection string). This is the most important setting. <\/li>\n\n\n\n<li>IPv4 would add that &#8220;4&#8221; in the connection string and will remove the IPV6 from the picture<\/li>\n<\/ul>\n\n\n\n<p>A good thing is to go on the remote machine and ensure the port you want it to listen to is bound to all addresses, connect,<strong> <code>su root<\/code> <\/strong>and then <code>run <strong>netstat -nat<\/strong><\/code> and here is what I see in my case: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"697\" height=\"107\" src=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-3.png\" alt=\"\" class=\"wp-image-128\" srcset=\"https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-3.png 697w, https:\/\/coding101.xyz\/wp-content\/uploads\/2024\/01\/image-3-300x46.png 300w\" sizes=\"auto, (max-width: 697px) 100vw, 697px\" \/><\/figure>\n\n\n\n<p>Clearly, 8080 bound to all the machine IPs<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This shows how to configure reverse SSH having a linux machine on the cloud, exposing a port on that one that is forwarded on your home machine at a specified port.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coding101.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=124"}],"version-history":[{"count":2,"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/posts\/124\/revisions"}],"predecessor-version":[{"id":130,"href":"https:\/\/coding101.xyz\/index.php?rest_route=\/wp\/v2\/posts\/124\/revisions\/130"}],"wp:attachment":[{"href":"https:\/\/coding101.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coding101.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coding101.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}