Hello,

I'll try to make this short. I've successfully been able to connect to my SSH server using Net::SSH2. All is dandy, except I had some issues trying to run commands and gather the output. So that had me trying Net::SSH:Any using the SSH2 backend. I cannot connect as I receive an authentication error. I think I have pegged it to an issue with the publickey file.

Net::SSH2 code:
$ssh2= Net::SSH2->new(); my $host = 'serveraddress'; my $port = 22; my $user = 'username'; $ssh2->connect($host, $port) or $ssh2->die_with_error; my $ppk_filepath = 'C:\Users\username\rsa-key-username'; print "$ppk_filepath exists!\n" if -e $ppk_filepath; $ssh2->auth_publickey($user, undef, $ppk_filepath, 'passphrase123' + ) or $ssh2->die_with_error;

This code works and I connect and can authenticate. But in fact, if I were to place my LOCAL publickey file path where undef currently is I would get authentication errors. I believe with undef it some how infers a .pub file from my private key. From SSH2.pm source:

"When libssh2 is compiled using OpenSSL as the crypto backend, passing this method C<undef> as the public key argument is acceptable (OpenSSL is able to extract the public key from the private one)."

use Net::SSH::Any; $Net::SSH::Any::debug = -1; my $host = 'serveraddress'; my $port = 22; my $user = 'username'; my $ppk_filepath = 'C:\Users\username\rsa-key-username'; $ssh2 = Net::SSH::Any->new($host, port => $port, user => $user, pa +ssphrase => 'passphrase123', key_path => $ppk_filepath, backends => ' +Net_SSH2'); if ($ssh2->error) { die "Connection error: " . $ssh2->error; }

Here I get an authentication error. I understand that it's looking for the .pub file, which I do have in the same directory as my privatekey file. Everything seems correct here. I've searched all over Google and Perl Monks for an answer and I appreciate all the info from Salva (that has helped me get Net::SSH2 up and running) but I cannot find too much about SSH::Any with SSH2 backend. Thanks for any help, from a beginnner.


In reply to Net::SSH::Any using SSH2 Backend and Public Key by Anonymous Monk

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.