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

I have a wrapper script which I wrote to work around hanging TTY issues when starting tomcat over SSH, but upong upgrading my system, it seems to have horribly broken key authentication. Here's the relevant snippet of perl code:

my %SSH_Prm = ( "protocol" => '2', "use_pty" => 0, "options" => ["stricthostkeychecking no"], "identity_files" => ["/home/user/.ssh/id_rsa"], "debug" => 1, ); my $ssh = Net::SSH::Perl->new($server,%SSH_Prm); $ssh->login("deploy"); my ($out,$err,$exit) = $ssh->cmd("/usr/bin/sudo $command");

The debug was added to get more detailed diagnostic data, which now shows:

server.domain.net: Authentication methods that can continue: publickey +. server.domain.net: Next method to try is publickey. server.domain.net: Trying pubkey authentication with key file '/home/u +ser/.ssh/id_rsa' server.domain.net: Authentication methods that can continue: publickey +. server.domain.net: Next method to try is publickey. Permission denied at ./start_tomcat_remote line 88

Now if I test this ssh key authentication using OpenSSH, it works without issue:

ssh -vv -i /home/user/.ssh/id_rsa deploy@server.domain.net ... debug1: Offering public key: /home/user/.ssh/id_rsa debug2: we sent a publickey packet, wait for reply debug1: Server accepts key: pkalg ssh-rsa blen 277

Now to my eye, this is a very straightforward perl module failure, but I'm not getting enough information to figure out how to fix it. I've read through other perlmonks issues with Net::SSH::Perl and have found issues with password auth, but nothing else using pre-determined keys. Any idea what I might do next to resolve this?

Replies are listed 'Best First'.
Re: Key Auth problem with Net::SSH::Perl
by salva (Canon) on Jan 14, 2015 at 08:51 UTC
    No idea was going wrong with Net::SSH::Perl, but if you can connect using the OpenSSH client, its very likely you will also be able to connect using Net::OpenSSH

    You could also use Net::OpenSSH::Compat::Perl that implements most of Net::SSH::Perl API on top of Net::OpenSSH.