Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Net::SSH2 error - Username/PublicKey combination invalid

by BernieC (Pilgrim)
on Dec 13, 2018 at 02:05 UTC ( #1227197=perlquestion: print w/replies, xml ) Need Help??

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

I'm back playing with Net::SSH2 and running into trouble again. My code is still the very very simple
my $ssh2 = Net::SSH2->new() ; $ssh2->connect(HOST) or $ssh2->die_with_error ; $ssh2->check_hostkey(tofu => HOSTKEY) or $ssh2->die_with_error ; $ssh2->auth_publickey(USER, PUBLICKEY, PRIVATEKEY) or $ssh2->die_with_error ; $ssh2->auth_ok() ;

Here's what's happening: I have a real SSH client that uses a single SSH keyprofile for two different unix systems. I've double checked and the and authorized.keys files on both servers are identical. I have the two constants: HOST and USER. when I changed the HOST and USER to be the new system and the username to use on that system, I get

Username/PublicKey combination invalid (-18 LIBSSH2_ERROR_PUBLICKEY_UN +RECOGNIZED ) at D:\Perl\ line 28.
I have no idea what it is trying to tell me. What do usernames have to do with SSH keys?

Replies are listed 'Best First'.
Re: Net::SSH2 error - Username/PublicKey combination invalid
by salva (Canon) on Dec 13, 2018 at 09:57 UTC
    That probably means that the remote host has not accepted the given public key as valid for the user.
      Eli the Bearded <*> wrote: } Really does sound like the user/key pair isn't right. I've checked a bunch more -- I turned on logging in my SSH client and, indeed, it, too, fails. Grumble.

      Now I'm not sure why -- I *thought* perhaps incorrectly?? that SSH key pairs were server agnostic. That is, I thought/assumed that if my public/private key work on server A they'll work on server B. Apparently that is not the case and at the moment I have no clue why. So not a perl problem, which I might have had a chance of dealing with, but SSH key exchange problem about which I have no clue. Off to try to understand it.. Sorry to think this is a Perl problem... /Bernie\

        Problem solved! A unix-friend made a suggestion that proved to be correct: the authorized_keys file has to be non-writable. I had just copied in the key so it got some default protections. chmod 710 did the trick. Sorry to bother you guys...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (1)
As of 2022-01-28 05:15 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (73 votes). Check out past polls.