Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Net SSH2 auth_publickey not working in Windows

by karayan (Novice)
on Dec 15, 2008 at 20:31 UTC ( [id://730490]=perlquestion: print w/replies, xml ) Need Help??

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

Hello, I am trying to connect to a remote solaris machine from windows. I am unable to connect using Net::SSH2 auth_publickey. Does auth_publickey work in Windows? auth_password works fine for me. This is my code.
use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->debug(1); $ssh2->connect('hostname') or die; if ($ssh2->auth_publickey('username', 'openssh.public', 'openssh.priva +te.ppk')) { print "Connected"; } else { print "failed"; }
This fails all the time. I have used the same key successfully in Putty to connect to the server. The key files are on the same folder this script is. Also how can I get more verbose debug messages? Thanks in advance.
Regards,
Saura

Replies are listed 'Best First'.
Re: Net SSH2 auth_publickey not working in Windows
by kennethk (Abbot) on Dec 15, 2008 at 20:41 UTC
    Re: more verbose debug messages, in addition to the debug method you call, you can also call error to return the last error message and a description string - see Net::SSH2.
      Thanks, Error reported that it was unable to initialize private key from file. I was using puttygen for generate public private key. When I used private key from export opensshkey option in puttygen everything worked.
      Thanks for your help.
      Saura.
      PS: I am new here. How do I disable html messages here. I prefer plain text.
Re: Net SSH2 auth_publickey not working in Windows
by zentara (Archbishop) on Dec 15, 2008 at 20:44 UTC
    You might try and see if an error message is printed to the console
    $ssh2->auth_publickey('username', 'openssh.public', 'openssh.private.ppk') or die "$!\n";

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      Afternoon all.

      I'm having the same problem as above, same circumstances in that I can use puTTY to get on to the box using key-based authentication. The relevant code is:

      my $ssh = Net::SSH2->new();
      print "DEBUG: 1\n";
      $ssh->debug(1);
      $ssh->connect($config_host);
      print "DEBUG: 2 $SSH_USER\n";
      $ssh->auth_publickey($SSH_USER, './virt_pub', './virt_priv.ppk') or die "pk connection error $!\n";
      #$ssh->auth_password($SSH_USER, "some_password");
      print "DEBUG: 3\n";
      my $channel = $ssh->channel();
      print "DEBUG: 4 $ssh->error()\n";


      At the ->auth_publickey call I get the message 'Resource temporarily unavailable'.

      Does anyone know which resource? One of the key files or perhaps sshd on the server?

      TIA,

      Nick

      p.s. the auth_password version works
        Hi, I don't use windows, but compare your auth_publickey to mine below.
        $ssh->auth_publickey($SSH_USER, './virt_pub', './virt_priv.ppk') or di +e "pk connection error $!\n";
        # you need permission to read the keys $ssh2->auth_publickey('zentara', '/home/zentara/.ssh/id_dsa.pub', '/home/zentara/.ssh/id_dsa', $pass );
        It's possible that your dot slash notation for specifying the key's path, may need a full path from root. You may not be running from the directory you think you are in.

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh
        Right, it's working, thanks to both zentara and salva for gently nudging me in the right direction and apologies for the wetware error

        It was me using the wrong format keys. Once I used the private key generated from puttygen's 'Conversion' menu and the public key from the 'Public key for pasting into OpenSSH authorized_keys file' file all works swimmingly.

        Nick
Re: Net SSH2 auth_publickey not working in Windows
by taiko (Sexton) on Feb 29, 2016 at 11:32 UTC
    I experienced exactly same problem. How I resolved it is following.

    1. Generated SSH-2DSA dsa.pub and dsa.ppk with puttygen on Windows

    2. Converted dsa.ppk to openssh.ppk ( Conversion-> Export OPENSSH key) in puttygen

    3. Loaded openssh.ppk and saved openssh.pub from Key window in puttygen

    4. copied content openssh.pub to authorised_keys on server and on local windows computer

    5. Voila

    my $ssh2 = Net::SSH2->new(trace => -1); #$ssh2->debug(1); $ssh2->connect('server_ip') or die $!; print $ssh2->error; $ssh2->auth_publickey('username','openssh.pub','openssh.ppk') or die + "$!\n"; my $chan = $ssh2->channel(); $chan->blocking(0); $chan->exec('ls -al'); my @output; while (<$chan>) { print $_; }
    works with no problems

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (1)
As of 2024-04-16 15:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found