I've been using Net::SFTP::Foreign with the Net_SSH2 backend for username/password and private key authentication without error for a little while now but I've been recently tasked with adding in functionality to utilize passphrase protected private keys.

Net:SFTP::Foreign has an option for passphrase, according to CPAN, but when utilizing it I get the error "Invalid option 'passphrase' or bad combination of options at sftpTest.pl line 15".

It seems that Net::SFTP::Foreign passes the SFTP object's arguments directly to the Net_SSH2 backend and passphrase is not a recognized argument for the Net_SSH2 backend. Is that correct or am I way off base? If that is correct, is there a way to utilize passphrase protected private keys in Perl?

Below is my test script. Also, this has to be platform independent so utilizing the always useful linux command line arguments isn't an option. Thanks for any help.

use Net::SFTP::Foreign; my $host = 'localhost'; my $user = 'sshuser'; my $privateKey = "C:\\id_rsa"; my $file = "C:\\sshuser-results.xml"; my $passphrase = "password"; my $sftp = Net::SFTP::Foreign-> new(host => $host, backend => 'Net_SSH2', user => $user, key_path => $privateKey, passphrase => $passphrase, ); if( not $sftp) { $sftp->die_on_error("Unable to establish SFTP connection"); } elsif($sftp->error) { $sftp->die_on_error("Connect Failed: " .$sftp->status); } else { print "Connected!\n"; if($sftp->get("sshTest.txt")) { print "get success: " . $sftp->status . "\n"; } else{ print "get failed: " . $sftp->error . "\n"; } if($sftp->put($file)){ print "put file success \n"; } else{ print "put failed: " . $sftp->error . "\n"; } }

In reply to Net::SFTP::Foreign and Using Passphrases on Private Keys by swamprich

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.