NAME
Net::SSH::Tunnel - This is a simple wrapper around ssh to establish a tunnel. Supports both local and remote port forwarding.
VERSION
Version 0.04
SYNOPSIS
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.
SUBROUTINES/METHODS
new
The constructor. Creates an object, invokes init() for argument parsing
init
Arg parser. Sets default values, uses Getopt::Long then do the necessary parsing.
run
Driver method to do the new()->init() dance, then calls appropriate methods based on the args
setup_tunnel
Establishes a ssh tunnel based on the object info.
check_tunnel
Runs ps and finds an existing tunnel, according to the parameters supplied
destroy_tunnel
Calls check_tunnel() for existing tunnel, and if it exists, kills it.
usage
The sub to provide help.
AUTHOR
Satoshi Yagi, <satoshi.yagi at yahoo.com>
BUGS
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.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Net::SSH::Tunnel
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
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.