{"id":623,"date":"2018-07-06T22:56:40","date_gmt":"2018-07-06T20:56:40","guid":{"rendered":"http:\/\/itso.dk\/?p=623"},"modified":"2018-07-07T00:33:50","modified_gmt":"2018-07-06T22:33:50","slug":"persistent-network-tunnel-with-autossh","status":"publish","type":"post","link":"https:\/\/blog.itso.dk\/?p=623","title":{"rendered":"Persistent network tunnel with autossh"},"content":{"rendered":"<h4>Purpose an explanation:<\/h4>\n<p>This guide will help setup a reverse tunnel from one host behind a firewall, where you can not open a port to. With a little help from autossh connection will be persistant, even if connection breaks, autossh will make sure tunnel is reconnected.You will be able to connect to the normally unreachable server, with the usage of the remotehost jump-server.<\/p>\n<p>In this example, you can connect to a remotehost, that has a open or connectable ssh server on port 22. After logging in to the remote host, you can ssh from that to using the localhost port 25000 which will route the port to the system behind the firewall on port 22 ssh-server.<\/p>\n<h4>To pull of this trick, I have set up the following:<\/h4>\n<p>Install autossh and ssh-server<br \/>\ncreate ssh-key,<br \/>\ncopy ssh-key.pub,<br \/>\nconfigure config file.<br \/>\nconfigure crontab<\/p>\n<p>&nbsp;<\/p>\n<h4>Install autossh and server-ssh-server<\/h4>\n<p>On Ubuntu, log in as root, and enter the command:<\/p>\n<pre>apt install ssh autossh\r\nsystemctl enable sshd\r\nsystemctl start sshd<\/pre>\n<p>On FreeBSD log in as root, and enter the command:<\/p>\n<pre>pkg install autossh\r\n\r\nsysrc sshd_enable=\"YES\"\r\n\r\nservice sshd start<\/pre>\n<h4>Create SSH-key<\/h4>\n<pre>ssh-keygen -t ed25519<\/pre>\n<h4>Copy ssh-key.pub to remotehost<\/h4>\n<pre>ssh-copy-id -i .ssh\/id_ed25519.pub remotehost<\/pre>\n<h5>Configure config file<\/h5>\n<pre>nano \/root\/.ssh\/config\r\n\r\nHost <em>remote-tunnel-home<\/em>\r\nHostName <em>remotehost<\/em>\r\nUser <span style=\"text-decoration: underline;\"><em>remotehostuser<\/em><\/span>\r\nPort <em>22<\/em>\r\nIdentityFile ~\/.ssh\/<em>id_ed25519<\/em>\r\nRemoteForward <em>25000<\/em> localhost:<em>22<\/em>\r\nServerAliveInterval 30\r\nServerAliveCountMax 3<\/pre>\n<h5>Configure Crontab<\/h5>\n<pre>crontab -e\r\n@reboot \/usr\/local\/bin\/autossh -M 0 -N remote-tunnel-home &amp;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Purpose an explanation: This guide will help setup a reverse tunnel from one host behind a firewall, where you can not open a port to. With a little help from autossh connection will be persistant, even if connection breaks, autossh will make sure tunnel is reconnected.You will be able to connect to the normally unreachable &#8230;<\/p>\n<p><a href=\"https:\/\/blog.itso.dk\/?p=623\" class=\"more-link\">Continue reading &lsquo;Persistent network tunnel with autossh&rsquo; &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":634,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,8,1],"tags":[],"class_list":["post-623","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-freebsd","category-linux-tip","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.itso.dk\/index.php?rest_route=\/wp\/v2\/posts\/623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.itso.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.itso.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.itso.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.itso.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=623"}],"version-history":[{"count":12,"href":"https:\/\/blog.itso.dk\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions"}],"predecessor-version":[{"id":638,"href":"https:\/\/blog.itso.dk\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions\/638"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.itso.dk\/index.php?rest_route=\/wp\/v2\/media\/634"}],"wp:attachment":[{"href":"https:\/\/blog.itso.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.itso.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.itso.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}