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

*Trying to connect host 1 (windows xp) to host 2(fedora core8) via SSH and a public key. *Using Perl Activestate perl 5.10 *I tested first with password auth and was successful. *Trying to use a putty generated SSH2 -RSA keypair and it fails to connect. *The only change I have made from working to non working is the auth type, from password to key. Here is my code - Does anything appear to be wrong here?
#!/usr/bin/perl -w use strict; use Net::SSH2; my $buflen = 100; my $buf = '0' x $buflen; my $ssh2 = Net::SSH2->new(); $ssh2->connect('10.1.1.85','22') or die; #$ssh2->debug(1); $ssh2->auth_publickey('root','pub.pub','priv.ppk','toor') or die "Unable to login $! \n"; my $chan1 = $ssh2->channel(); $chan1->blocking(1); $chan1->exec('df'); $chan1->read($buf, $buflen); print "BUF: ", $buf, "\n"; $chan1->close; #my $chan2 = $ssh2->channel(); #$chan2->blocking(1); #$chan2->exec('echo $HOME'); #$chan2->read($buf, $buflen); #print "BUF: ", $buf, "\n"; #$chan2->close; system ("pause");

Replies are listed 'Best First'.
Re: net::ssh2 connection
by almut (Canon) on Nov 03, 2008 at 19:44 UTC
    #$ssh2->debug(1);

    Do you get anything useful if you enable this?  If not, you might try enabling debugging for the server side, too (if you have the appropriate permissions on the Fedora box, that is).

      C:\Perl>perl ssh2.pl Unable to login Net::SSH2::DESTROY object 0x1a44f1c
      The Fedora box is just my test box so I will put it into debug as well and see what I can get.
        Okay, Debugged the server. My server accepts the key just fine. The connection is closed by my WinXp box.
        Connection closed by "my authenticating host" dispatch_protocol_error: type 90 seq 5 fatal: read from socket failed:connection reset by peer
        Unable to login

        I was wondering if there could be a problem with the way that auth_publickey() reads file with windows line endings. In the libssh2 library, the public file is read with:
        while (!feof(fd) && (c = fgetc(fd)) != '\r' && c != '\n') pubkey_len++;
        I was thinking that perhaps, for windows line endings, that needs to be:
        while (!feof(fd) && (c = fgetc(fd)) != '\r' && c != '\n' && c != 10) pubkey_len++;
        I guess you could check that by storing the keys in files with nix line endings, and see if that makes any difference. Other than that, it might be useful to find out what  dispatch_protocol_error: type 90 seq 5 actually means. (Or it might not :-)

        Cheers,
        Rob