Net::SSH::Tunnel - This is a simple wrapper around ssh to establish a tunnel. Supports both local and remote port forwarding.
Perl module to setup / destroy a ssh tunnel.
create a very short driver script. $ vi driver.pl #!/usr/bin/perl use strict; use warnings; use Net::SSH::Tunnel; Net::SSH::Tunnel->run(); run the driver script with options. $ ./driver.pl --host dest.example.com --hostname hostname.example.com the above is equivalent to creating a local port forwarding like this: ssh -f -N -L 10000:dest.example.com:22 <effective username>@hostname.example.com after the driver script is done, you can then do: ssh -p 10000 user@localhost other usages: Usage: ./driver.pl --port 10000 --host dest.example.com --hostport 22 --hostname hostname.example.com Sets up a ssh tunnel. Works on both local and remote forwarding. In the example above, it will create a tunnel from your host to hostname.example.com, where your local port 10000 is forwarded to dest.example.com's port 22. --hostname specify the host where you create a tunnel from your host --host specify the destination of port forwarding --user user when connecting to <hostname>. default: effective user --type specify local or remote, for forwarding. default: local --hostport target port on <host>. default: 22 --port source port for forwarding. default: 10000 --sshport equivalent of -p <port> in ssh client. default: 22 --action 'setup' or 'destroy' a tunnel. default: setup --help prints the usage and exits --debug turn on debug messages Notes on testing: This module wraps around ssh and as such, requires authentication. I have included test_deeply.pl that asks for hostnames, runs ssh and establishes a tunnel. If you'd like to test manually, please use the script.
The constructor. Creates an object, invokes init() for argument parsing
Arg parser. Sets default values, uses Getopt::Long then do the necessary parsing.
Driver method to do the new()->init() dance, then calls appropriate methods based on the args
Establishes a ssh tunnel based on the object info.
Runs ps and finds an existing tunnel, according to the parameters supplied
Calls check_tunnel() for existing tunnel, and if it exists, kills it.
The sub to provide help.
<satoshi.yagi at yahoo.com>
Please report any bugs or feature requests to
bug-net-ssh-tunnel at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-SSH-Tunnel. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
You can also look for information at:
Copyright 2012-2013 Satoshi Yagi.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.