ssh https://tech.feedyourhead.at/ en SSH: transfer files indirectly using scp https://tech.feedyourhead.at/node/144 <span class="field field--name-title field--type-string field--label-hidden">SSH: transfer files indirectly using scp </span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Many times I have to remotely transfer files between 2 Hosts. And sometimes those hosts are not able to communicate to each other. In order to copy a file from host1 to host2 I had to copy it to my workstation first. But this is not necessary...<br />  </p> <p>It is possible to execute scp like this:</p> <p><img alt="host2host-&gt; scp user@host1:/somefile user@host2:/somefile" data-entity-type="file" data-entity-uuid="00b20d7d-0c2c-4b03-9403-3b757cc7c8c2" src="/sites/default/files/inline-images/host2host-scp_0.png" /></p> <p>In this example host1 and host2 are able to communicate together(user exist and perhaps ssh-keys too). I execute scp on host3 but the files are copied between host1 and host2. But what if host1 and host2 are not able to contact each other? For those cases I found a wonderful scp-switch in the manual:</p> <blockquote> <p>    -3      Copies between two remote hosts are transferred through the local host.  Without<br />              this option the data is copied directly between the two remote hosts.  Note that<br />              this option disables the progress meter.</p> </blockquote> <p><br /><img alt="redirected -&gt; scp -3 user@host1:/somefile user@host2:/somefile" data-entity-type="file" data-entity-uuid="75f548cd-f7bd-4636-b40b-11f4a8cd3fc4" src="/sites/default/files/inline-images/redirected-scp.png" /></p></div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Jan 15 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ssh" hreflang="en">ssh</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/tricks" hreflang="en">Tricks</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=144&amp;2=comment&amp;3=comment" token="kGhyXRjxKgIZUFwM4OSLk4RJtCvZGBBdHZgDTVjBhOk"></drupal-render-placeholder> </section> Fri, 15 Jan 2016 09:37:34 +0000 Hoti 144 at https://tech.feedyourhead.at SSH: Creating a reverse tunnel https://tech.feedyourhead.at/content/ssh-creating-reverse-tunnel <span class="field field--name-title field--type-string field--label-hidden">SSH: Creating a reverse tunnel</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Let's assume we have a workstation behind a firewall(NAT) and this workstation isn't directly reachable&nbsp; from internet. If we want to connect to this&nbsp; workstation from outside, we have to do some tricky things. SSH has an option to create reverse-tunnels. We can connect from this workstation to any ssh-server in internet and we can use that connection to to get back to the workstation.</p> <p><img alt="" src="http://tech.feedyourhead.at/sites/tech.feedyourhead.at/files/pictures/ReverseSSH.png" /><br /> &nbsp;</p> <p>Just to make it clear: we have a <strong>workstation</strong> out in the internet which is behind a Firewall(NAT). We also have a <strong>host</strong> which is behind a Firewall(NAT). And we have a <strong>public SSH-Server</strong> which is reachable from both. You can see that constellation at the picture above.</p> <h4>First we create the Reverse-Tunnel from Host and bind it to Port 2222 at our public SSH-Server:</h4> <pre> <code> ssh -R 2222:localhost:22 cooluser@93.40.10.2 </code></pre> <p>It's important to keep this ssh-session open! I would also recommend to keep the session alive using the command "<em>watch -n 5 date</em>"</p> <h4>Now our workstations also connects to our public SSH-Server:</h4> <pre> <code> ssh cooluser@93.40.10.2 </code></pre> <h4>If we are connected from our workstation to our public SSH-Server, we can now use the Reverse-Tunnel to connect to the host:</h4> <pre> <code> ssh hostuser@localhost -p 2222 </code></pre> <p>You might have recognized that the user has changed. Now we are using any user which exists at our target host.</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Sep 11 2015</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ssh" hreflang="en">ssh</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/tricks" hreflang="en">Tricks</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/network" hreflang="en">Network</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=91&amp;2=comment&amp;3=comment" token="YwgHS-LCDb_Q9b7iBwPzs1DFMKlXOZP2gM97Z2nh3X8"></drupal-render-placeholder> </section> Fri, 11 Sep 2015 07:00:45 +0000 Hoti 91 at https://tech.feedyourhead.at