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

Hi,

So I am reading Net::OpenSSH cpan doc and I'm not quite getting something. Perhaps someone could help me out with an example?

Goal: ssh from machineA to machineB and execute "uname -a", while using machineC as the jumpbox between the two.

Any help's appreciated!

Replies are listed 'Best First'.
Re: Net::OpenSSH and tunnels
by salva (Canon) on Dec 02, 2010 at 09:53 UTC
    Read the documentation for ProxyCommand directive in the ssh_config manual.

    If netcat (or socat or some similar utility) is available in machine C, then it can be done as follows:

    my $ssh = Net::OpenSSH->new($host, master_opts => [-o "ProxyCommand ssh machi +neC /usr/bin/nc %h:%p"]);

    Otherwise, if perl (or any other scripting language) is available on machine C, you could write a netcat clone yourself with it.

    As a last resort, you can use this (not very efficient) ProxyCommand:

    ProxyCommand ssh machineC ssh -p %p %h sshd -i
    If you want to use password authentication between machine A and machine C, you will have to do it using an auxiliary Net::OpenSSH object.

    Post the full details of your setup and I will be able to provide further instructions on how to do it.

    update: oh, and of course, you can use ssh to create a tunnel from machine A to B through C if they are not administratively forbidden in machine C... in my experience, something very unlikely.