{"id":1033,"date":"2013-11-06T20:29:19","date_gmt":"2013-11-06T20:29:19","guid":{"rendered":"http:\/\/cyber-cottage.co.uk\/en\/?p=1033"},"modified":"2014-11-16T20:44:34","modified_gmt":"2014-11-16T20:44:34","slug":"remote-ssh-tunnel-script","status":"publish","type":"post","link":"https:\/\/www.cyber-cottage.co.uk\/?p=1033","title":{"rendered":"Remote ssh tunnel script"},"content":{"rendered":"<p>We have various customers that have firewalls that only allow known trusted IP addresses through. Normally our office and our monitoring platform for example.<\/p>\n<p>But if we are out and about we still sometimes need to access a system and its GUI, so we have created the simple script below that makes a ssh connection to the customer server and also tunnel to access any web gui.<\/p>\n<p>This script is in place on the monitoring server so we can just ssh in to the monitoring platform and run the script. all that is needed is a single tunnel setup on the ssh client that i&#8217;m accessing the monitoring platform from.<\/p>\n<pre>#!\/bin\/bash\necho ssh tunnel tool. 2013 cyber-cottage.co.uk\necho Setting up a tunnel to $1\nwhois $1 |grep netname\nif [ \"$1\" = '' ]; then\n echo \"You have no remote destination set\"\n echo \"usage: remotetunnel.sh &lt;remote server&gt; &lt;remote ssh port&gt; &lt;remote system port&gt;\"\n echo \"For example remotetunnel.sh 81.22.23.24 8022 80\"\n exit\nfi\nif [ \"$3\" = '' ]; then\necho \"usage: remotetunnel.sh &lt;remote server&gt; &lt;remote ssh port&gt; &lt;remote system port&gt;\"\necho \"For example remotetunnel.sh 81.22.23.24 8022 80\"\nif [ \"$2\" = '' ]; then\n echo \"You have no remote ssh or system port set, Setting ssh to port 22\"\n port=\"22\"\nelse\n port=\"$2\"\nfi\n echo \"You have no remote system port set, Setting remote to port 80\"\n rport=\"80\"\nelse\n rport=\"$3\"\nfi\nif [ \"$port\" = '' ]; then\n port=$2\nfi\necho Remote system IP is $1\necho Remote ssh port is $port\necho Remote system port is $rport\nread -p \"Is this correct? (y\/n) \" RESP\nif [ \"$RESP\" = \"y\" ]; then\n echo \"Glad to hear it\"\nelse\n exit\nfi\nssh -L 9999:localhost:$rport \u00a0$1 -oport=$port<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We have various customers that have firewalls that only allow known trusted IP addresses through. Normally our office and our monitoring platform for example. But if we are out and about we still sometimes need to access a system and its GUI, so we have created the simple script below that makes a ssh connection [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11,82],"tags":[23,35,40,51,73,100],"class_list":["post-1033","post","type-post","status-publish","format-standard","hentry","category-knowledge","category-security-knowledge","tag-asterisk","tag-elastix","tag-freepbx","tag-linux","tag-support","tag-technical"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p5daZy-gF","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1033","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1033"}],"version-history":[{"count":2,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1033\/revisions"}],"predecessor-version":[{"id":1289,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1033\/revisions\/1289"}],"wp:attachment":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}