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

I was wondering if someone could push me in the right direction to using the Net::SSH::Perl module to forward a local port to a port on a remote machine via ssh.

I am looking for the same functionality of the unix/linux ssh client with the -L arguement.

Such as:

ssh -l username hostname -L 3333:hostname:5432

If you can't tell I pulled that from the postgresql documentation and thats exactly what I would like to do with this perl module. I would like to have "built-in" encrypted traffic for my database connection with my application.

Any general information (or specific if you wanna be really really nice) would be really really really appreciated.

Thanks!!!

Replies are listed 'Best First'.
Connecting to PostgreSQL with SSL using DBD::Pg
by Arguile (Hermit) on Jun 09, 2003 at 02:00 UTC

    This isn’t answering your question for Net::SSH::Perl, but if you’re simply interested in SSL connections to PostgreSQL you can do that through DBD::Pg.

    To do that, follow these steps:

    1. Build and install an SSL enabled PostgreSQL (requires OpenSSL) - DOCS
    2. Configure the certificates - DOCS
    3. Build and install DBI - DOCS
    4. Build and install DBD::Pg - DOCS
    5. Require SSL on that connection - DOCS

    It might seem a bit complex, but it’s very easy when you step though it. And when you’re done, using SSL to connect is simple and transparent.

    Note: Make sure to read the DBD::Pg README on including the SSL lib (linked above).

      Although that still may be an option and sounds good. (I'll need to do some research) I have other databases that I need to connect to other than just Postgres. (DB2 8.1) I'm more familiar with Postgres than I am DB2 so I'll check into that.

      Thanks for the input.
      Actually now that I thought about the situation more. It would be possible for me to use SSL for my postgres database and force any connection to it to be SSL.

      In my particular situation I could not require the same of my DB2 database. I have other applications (that don't know how to use SSL and can't be changed) that require the ability to access the DB2 database.

      I need my application to be able to access both of these. I am fairly familiar with DBI and with basic Perl programming, I however have little experience with Perl network programming.

      Could I possibly use IO::Socket to collect the data that comes in on my local machine on port 3333 then use the Net::SSH::Perl::Packet to send the information across the SSH connection? I am a bit confused on how I could specify the remote port in which to forward the data to.

      I'm not sure if I'm looking in the right direction for this or not, or if it is even possible at this point with this particular module.I think I need to grab me a Perl networking book....

      Please keep any input coming.. I'm diggin for ideas
Re: Port Forwarding with Net::SSH::Perl?
by zentara (Cardinal) on Jun 09, 2003 at 13:14 UTC
    It's not Perl, but it will probably do what you want. stunnel