Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

openssh start another ssh session on machine b

by jhuijsing (Acolyte)
on Mar 27, 2014 at 05:42 UTC ( [id://1079879]=perlquestion: print w/replies, xml ) Need Help??

jhuijsing has asked for the wisdom of the Perl Monks concerning the following question:

Help needed with Net::openSSH

I can open a ssh session to machine b. How can open a ssh session from machine b to machine c?

  • Comment on openssh start another ssh session on machine b

Replies are listed 'Best First'.
Re: openssh start another ssh session on machine b
by salva (Canon) on Mar 27, 2014 at 08:47 UTC
    You can use the ProxyCommand feature of OpenSSH (requires tunnels enabled on host b and a relatively recent version of OpenSSH on the local host):
    my $ssh_b = Net::OpenSSH->new($host_b, ...); $ssh_b->error and die; my $tunnel_cmd = $ssh_b->make_remote_command({tunnel => 1}, $host_c, 2 +2); my $ssh_c = Net::OpenSSH->new($host_c, master_opts => [-o => "ProxyCom +mand=$tunnel_cmd"], ...); $ssh_c->error and die; $ssh_c->system('ls');
    Another option is to install Net::OpenSSH::Gateway available from GitHub.
    my $ssh_c = Net::OpenSSH->new($host_c, gateway => { proxy => "ssh://$h +ost_b"}, ...);
    That module implements a set of strategies to forward SSH connections over different kinds of proxies including SSH gateways. It is not on CPAN because I was not happy with its internal architecture and planed to revamp it completely but unfortunately, I never got the time (or the guts) to actually do it and it has languished there. In any case I would fix any bug reported.
      Can't install anything on machine "B" easily. Have to get vendor approval. What I need to do is ssh to "B" and then ssh to a different port on the "B" to start a CLI session.
        Neither of the two methods exposed on my previous post require installing anything on host B. Everything is done in host A.
Re: openssh start another ssh session on machine b
by zentara (Archbishop) on Mar 27, 2014 at 10:07 UTC
Re: openssh start another ssh session on machine b
by Anonymous Monk on Mar 27, 2014 at 06:22 UTC
    is easy, you run a program on machine b, which opens a connection to machine c
      not very helpful

      but is probably my own fault. Brains not firing on all cylinders.

      Yes I could do openssh->system call. But I need to pass a user name and password (cannot not use keys) and some other options.

      I just don't know enough about how use the pty. so that i can start another ssh session and pass the options I need

        ... cannot not use keys ... I just don't know enough about how use the pty. so that i can start another ssh session and pass the options I need

        Did you try something? What happened?

        I would do  system qw[  thenewprogram.pl usrname password whateverelseiyouneed  ]; ...

        or Proc::Background if needed

        And inside thenewprogram.pl just do regular old   Net::OpenSSH->new('username:password@hostname.example'); ... error checking ...

        and ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1079879]
Approved by salva
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-20 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found