Satoshi Yagi
and 1 contributors


Net::SSH::Tunnel - This is a simple wrapper around ssh to establish a tunnel. Supports both local and remote port forwarding.


Version 0.04


Perl module to setup / destroy a ssh tunnel.

    create a very short driver script.
    $ vi

    use strict;
    use warnings;
    use Net::SSH::Tunnel;

    run the driver script with options.
    $ ./ --host --hostname
    the above is equivalent to creating a local port forwarding like this:
    ssh -f -N -L <effective username>

    after the driver script is done, you can then do:
    ssh -p 10000 user@localhost
    other usages:
    Usage: ./ --port 10000 --host --hostport 22 --hostname
    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, where your local port 10000 is forwarded to'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 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, <satoshi.yagi at>


Please report any bugs or feature requests to bug-net-ssh-tunnel at, or through the web interface at 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.

    perldoc Net::SSH::Tunnel

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 for more information.