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

use strict; use warnings; use Net::SSH::Perl; use Net::SSH::Perl::Auth; use Net::SSH::Perl::Auth::RSA; use Net::SSH::Perl::Auth::PublicKey; use Net::SSH::Perl::Agent ; my @ids = ("/home/abc/.ssh/id_rsa"); my %params = ( 'protocol' => 2, 'interactive' => 1, 'identity_files' = +> \@ids, ); my $host = "server"; my $login = Net::SSH::Perl->new($host, %params)|| die "could not creat +e ssh object for host"; my $auth = Net::SSH::Perl::Auth->new('PublicKey', $login) || die "coul +d not create Auth object"; $auth->authenticate;
I am trying to do the Public Key Authemtication. But I am hetting an error saying "Can't call method "agent" on an undefined value at /usr/local/lib/perl5/site_perl/5.18.0/Net/SSH/Perl/Auth/PublicKey.pm line 42.". not sure why it is exiting as soon as it calls $auth_authenticate() thnaks --girija

Replies are listed 'Best First'.
Re: problem with Net::SSH::Perl using dsa key authenticatio
by AppleFritter (Vicar) on Jul 25, 2014 at 10:09 UTC

    I've never worked with Net::SSH::Perl, but looking through its code, I'm getting a feeling you may need to call $login->login() before authenticating. This seems counterintuitive to me, but apparently login() (well, _login()) is what sets the AuthMgr on a Net::SSH::Perl::SSH2 object in the first place.

    I'm afraid I can't try it, but it should be a starting point for further investigation.

Re: problem with Net::SSH::Perl using dsa key authenticatio
by Mr. Muskrat (Canon) on Aug 04, 2014 at 21:04 UTC

    I don't have any trouble using a DSA key but for the life of me cannot get it to use an RSA key as you have done.

    Here is my working (but scrubbed) DSA key script.

    #!/bin/env perl use strict; use warnings; use Net::SSH::Perl; my @ids = ('/path/to/id_dsa'); my %params = ( protocol => 2, interactive => 1, identity_files => \@ids, debug => 1, ); my $host = 'somehostwithssh'; my $ssh = Net::SSH::Perl->new( $host, %params ) or die "Could not crea +te SSH object for $host\n"; $ssh->login('username'); my ( $out, $err, $exit ) = $ssh->cmd( 'ls /tmp' ); print "out: $out\n" if defined $out; print "err: $err\n" if defined $err; print "exit: $exit\n" if defined $exit;