Was anyone able to do something similar to this ?
Yes, but not by using Net::*. (That doesn't mean it's not possible with Net::*, I just never tried). I just set up a tunnel. Here's a (cleaned) section of my ssh config file. It actually creates tunnels through *2* intermediate hosts:
Host = * ControlMaster = auto ControlPath = /home/javafan/.ssh/ssh_%h_%p_%r Host = gateway1 HostName = gateway1.example.com User = javafan ForwardAgent = yes ServerAliveInterval = 60 Host = gateway2 Hostname = gateway2.example.com User = javafan ForwardAgent = yes ProxyCommand = ssh gateway1 nc %h %p Host = *.example.com ForwardAgent = yes User = javafan ProxyCommand = ssh gateway2 nc %h %p
You may have to tweak it before it works for you.
The only way I see it to connect to the first host, then run ssh command in the remote shell. Unfortunately doing it this way will stop ssh-agent auth working and I will have to resort to passwords. thanks a lot for your helpful tips
Nah. At work, I often have to "hop" from machine to machine to get to the target machine, and as long as you use ssh -A, or have the appropriate ForwardAgent = yes entries in your ssh config files, ssh-agent authentication just works.

But this is way outside the realm of Perl.


In reply to Re: Establishing SSH tunnel and opening another SSH connection through it by JavaFan
in thread Establishing SSH tunnel and opening another SSH connection through it by tehcook

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.