in reply to net::ssh::perl Wrong key type

I will take a guess on this and say that Net::SSH::Perl wants to load a public key at that point (maybe it wants both keys?) and is complaining because you gave it a private key. I base this on the error originating from Net::SSH::Perl::Auth::PublicKey, although I have not used this package myself, so I may be completely wrong.

Try setting identity_files => ['client_key', 'client_key.pub'] and see if that helps.

Replies are listed 'Best First'.
Re^2: net::ssh::perl Wrong key type
by jpsaraiva (Acolyte) on Aug 23, 2019 at 08:48 UTC
    Hi jcb,

    Thank you for the pointer, unfortunatelly it does not work.

    I've seen that on other modules like Net::SSH2, auth_publickey expects the path for both public and private keys.

    It appears not to be the case with Net::SSH::Perl. Adding the public key does not change the outcome:

    my %params = ( "protocol" => '2', "use_pty" => 0, "options" => ["stricthostkeychecking no"], "identity_files" => ["client_key","client_key.pub"], "debug" => 1, ); $ssh = Net::SSH::Perl->new($server, %params);# debug=>1, identity_file +s=>\@KEYFILE); $ssh->login();
    localhost: Authentication methods that can continue: publickey,passwor +d,keyboard-interactive. localhost: Next method to try is publickey. localhost: Trying pubkey authentication with key file 'client_key' Wrong key type at C:/Strawberry/perl/site/lib/Net/SSH/Perl/Auth/Public +Key.pm line 83.

    If I try having the public key in the first place it just fails and tries the next one:

    localhost: Next method to try is publickey. localhost: Trying pubkey authentication with key file 'client_key.pub' Use of uninitialized value $object in substitution (s///) at C:/Strawb +erry/perl/site/lib/Net/SSH/Perl/Key.pm line 109. Use of uninitialized value $object in substitution (s///) at C:/Strawb +erry/perl/site/lib/Net/SSH/Perl/Key.pm line 109. localhost: Will not query passphrase for 'client_key.pub' in batch mod +e. Use of uninitialized value $object in substitution (s///) at C:/Strawb +erry/perl/site/lib/Net/SSH/Perl/Key.pm line 109. Use of uninitialized value $object in substitution (s///) at C:/Strawb +erry/perl/site/lib/Net/SSH/Perl/Key.pm line 109. localhost: Loading private key failed. localhost: Trying pubkey authentication with key file 'client_key' Wrong key type at C:/Strawberry/perl/site/lib/Net/SSH/Perl/Auth/Public +Key.pm line 83.

    I'm going to try all the key formats I manage to generate to check if there any issue there, since I don't know what else might be causing the problem.

    Regards.

      Found out a format that worked!

      ssh-keygen by default generates keys like:

      -----BEGIN OPENSSH PRIVATE KEY----- ...

      I tried other combinations until I found one that worked:

      $ openssl genrsa -out privatekey -----BEGIN RSA PRIVATE KEY----- ... $ chmod 600 privatekey $ ssh-keygen -y -f privatekey > publickey

      Running the script again, results in a successful login:

      localhost: Trying pubkey authentication with key file 'privatekey' localhost: Login completed, opening dummy shell channel. localhost: channel 0: new [client-session] localhost: Requesting channel_open for channel 0.