in reply to Re: Can't get $ssh2->check_hostkey to work
in thread Can't get $ssh2->check_hostkey to work

I tried turning on debugging in SSH2 and I'm not sure what it is telling me but there seems to be a hint at the problem.

d:\Desktop>sshtest libssh2_knownhost_init(ss->session) -> 0x294be38 Net::SSH2::KnownHosts::DESTROY Authentication failed (username/password) (-18 LIBSSH2_ERROR_PUBLICKEY +_UNRECOGNI ZED) at D:\Desktop\sshtest.pl line 13. Net::SSH2::DESTROY object 0x247cf08

It looks almost as though the problem is that the knownhost info is being destroyed before I get to the auth step. The code is

my $ssh2 = Net::SSH2->new(debug => 1); $ssh2->connect("shell02.theworld.com") or $ssh2->die_with_error ; $ssh2->check_hostkey('ask', "d:/profiles/known_hosts.pub") or $ssh2->die_with_error ; $ssh2->auth_password($login{user}, $login{password}) or $ssh2->die_with_error;

As if the check_hostkey works and so doesn't "die" but the fact that it works is lost before I do the auth. It is probably a rough trip, but I guess I should take a look at the code for auth_password and see what it is expecting for its public key check, and then work backwards to see what check_hostkey is supposed to leave behind to make auth_password happy. Everything is so hard...:o)

Replies are listed 'Best First'.
Re^3: Can't get $ssh2->check_hostkey to work
by BernieC (Pilgrim) on Aug 10, 2018 at 06:52 UTC
    I've switched over to Net::SSH::Perl to see if that is any better. I turned on its debugging machinery
    {...} Bernie-7-PC: Host 'shell02.theworld.com' is known and matches the host + key. Bernie-7-PC: Verifying server signature. Bernie-7-PC: Send NEWKEYS. Bernie-7-PC: Waiting for NEWKEYS message. Bernie-7-PC: Enabling encryption/MAC/compression. Bernie-7-PC: Sending request for user-authentication service. Bernie-7-PC: Service accepted: ssh-userauth. Bernie-7-PC: Trying empty user-authentication request. Bernie-7-PC: Authentication methods that can continue: publickey,keybo +ard-inter ctive. Bernie-7-PC: Next method to try is publickey. Permission denied at D:\Desktop\sshtest.pl line 15.
    It appears that the server won't accept a "password"! I don't exactly know why it says "empty authentication" and doesn't seem to try sending my password. The code is simple
    my $ssh = Net::SSH::Perl->new("shell02.theworld.com", protocol => 2, debug=>1, strict_host_key_checking => "no", options => ["PasswordAuthentication yes +"] ) ; $ssh->login($login{user}, $login{password}) ;
    I'll have to read up on what happens with the SSH "user-authentication service" and try to understand what's happening there. I can see why everyone who has been successful with SSH has reverted to using publickey auth..:o)
      Hi, you should check the settings on the SSH host you are trying to connect to. Usually its in /etc/ssh. For security reasons, many ssh servers disable root login, and many disable password logins, to force you to use keys. Read your ISP's HELP on ssh connections, or if you are in full control of the server, check out the settings in your ssh config files for the login types allowed. Your error message "Can't get $ssh2->check_hostkey to work" may be due to the fact that you don't have your keys setup properly. See setting up host keys

      I'm not really a human, but I play one on earth. ..... an animated JAPH
      The SSH protocol provides two authentication methods, password and keyboard-interactive, accepting a user/password pair. They look the same to the user but under the hood are quite different and not interchangeable.

      In your particular case, the server is accepting k-i,and you are trying to authenticate using password authentication.

        salva, I'm not BernieC, but when answering in another thread, I saw something, in this simplified SSCCE:

        #!/usr/bin/env perl # abbreviated version of https://perlmonks.org/?node_id=1220377 use warnings; use strict; use Net::SSH2 ':all'; use Config; print STDERR "\n__DATA__\n\n"; print STDERR "\$] => $]\n"; print STDERR "$_ => $Config{$_}\n" for qw/archname osname osvers/; print STDERR "\n\nshell02.theworld.com:\n"; my $ssh2 = Net::SSH2->new(); my $rv = $ssh2->connect('shell02.theworld.com') or $ssh2->die_with_err +or; $rv = $ssh2->auth_list() or $ssh2->die_with_error; + print STDERR "\tauth_list => $rv\n"; $rv = $ssh2->auth_password_interact('dummyuser') or $ssh2->die_with_er +ror; print STDERR "\tauth_password_interact +=> $rv\n"; # this wouldn't work on my strawberry perl: "Non-blocking ReadLine + is not supported on this architecture" __DATA__ $] => 5.026002 archname => MSWin32-x64-multi-thread osname => MSWin32 osvers => 10.0.16299.371 shell02.theworld.com: auth_list => publickey,keyboard-interactive dummyuser's password? Non-blocking ReadLine is not supported on this a +rchitecture at C:/usr/local/apps/berrybrew/perls/5.26.2_64_PDL/perl/v +endor/lib/Net/SSH2.pm line 314.

        Do you know of a way to get auth_password_interact() to work with Strawberry Perl's version of ReadLine?