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

$ssh2->check_hostkey(Net::SSH2::LIBSSH2_HOSTKEY_POLICY_ASK(), "d:/prof +iles/known_hosts.pub") or $ssh2->die_with_error ;

Net::SSH2::LIBSSH2_HOSTKEY_POLICY_ASK() doesn't work for me - complains about the absence of Term::ReadKey.
But the following works fine for me on Windows 7 with Strawberry Perl so long as I've established a connection to the host:
$ssh2->check_hostkey('advisory', "C:/Cygwin/home/user/.ssh/known_hosts +") or $ssh2->die_with_error ;
However, auth_password() still fails for me with that same error about the unknown username/public key combo.
For authentication I need to use auth_publickey.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Can't get $ssh2->check_hostkey to work
by BernieC (Pilgrim) on Aug 10, 2018 at 05:52 UTC

    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)

      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.