in reply to Re: How do you use Net::OpenSSH to query mysql database via ssh tunnel
in thread How do you use Net::OpenSSH to query mysql database via ssh tunnel

Net::OpenSSH does not directly supports creating TCP redirections, but they can be created using ssh forward control command:
$ssh->system({ssh_opts => [-O => 'forward', '-L4022:localhost:22']})

Replies are listed 'Best First'.
Re^3: How do you use Net::OpenSSH to query mysql database via ssh tunnel
by haukex (Archbishop) on May 09, 2017 at 18:52 UTC

    Thanks! If I understand correctly, with this command, the tunnel just stays open as long as the master process is running?

    Revised code:

    use Net::OpenSSH; my $ssh = Net::OpenSSH->new($host); die $ssh->error if $ssh->error; $ssh->system({ssh_opts => ['-O','forward', '-L127.0.0.1:12345:127.0.0.1:3306' ] }) or die $ssh->error;
      Yes, it will stay open until the master process finishes or you ask it to close the tunnel sending a cancel control:
      $ssh->system({ssh_opts => ['-O', 'cancel', '-L127.0.0.1:12345:127.0.0. +1:3306']});