Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Net::SSH::Any using SSH2 Backend and Public Key

by Anonymous Monk
on Sep 02, 2016 at 18:34 UTC ( [id://1171083]=perlquestion: print w/replies, xml ) Need Help??

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

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.

Replies are listed 'Best First'.
Re: Net::SSH::Any using SSH2 Backend and Public Key
by Anonymous Monk on Sep 02, 2016 at 19:18 UTC

    Hello, this is OP

    Actually I just solved my problem. This may have been obvious to any who might have read this but the issue was with the pub key itself. It was generated from puttygen. So I created a new pub key from my private key using ssh-keygen and now it works fine. Sorry to waste anyone's time!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1171083]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-24 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found