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

Hi Monks, I'm a begineer in perl. I need to collect some data from remote servers. My problem is with the identity file. Since the servers are not added into the identity_files , my script is failing.This is the first time I'm trying to login these servers. Following is the error message. Permission denied at connect.pl line 57 Its not even prompting to add the entry. I have around 200 servers. Is there any work around to solve this issue. Thanks in advance.
  • Comment on Failed to connect the server using Net::SSH::Perl

Replies are listed 'Best First'.
Re: Failed to connect the server using Net::SSH::Perl
by salva (Canon) on Apr 19, 2010 at 14:42 UTC
    Post your script source code and its output so we can see what you are doing at line 57, please!

    Anyway, I guess your problem is that your host keys are not listed on ~/.ssh/known_hosts. You can add them as follows:

    my @hosts = qw(foo1.bar.com foo2.bar.com ...); for (@hosts) { system "ssh $_ -o PreferredAuthentications=publickey -o StrictHostKe +yChecking=no true" }
      $ssh->login($username,$password); this is the 57th line. If I'm using system "ssh ... " it will work fine. I'm trying to use it through Net:SSH::Perl I dont want to use the shell script inside the perl script.
        You only need to run the code I posted before once in order to populate ~/.ssh/known_hosts, after that, your script using Net::SSH::Perl would be able to connect to any host.

        update: it seems that Net::SSH::Perl looks for the host keys in ~/.ssh/known_hosts2. I don't know if just copying the entries saved by your system SSH client from ~/.ssh/known_hosts to ~/.ssh/known_hosts2 will work.

Re: Failed to connect the server using Net::SSH::Perl
by Corion (Patriarch) on Apr 19, 2010 at 13:36 UTC

    Does connecting work from outside of Perl?

    This sounds to me more like an issue to take up with your system administrators than with Perl.

      yes, I'm able to login to the servers using ssh. Once I use ssh from cmd line the entry will be added in the identity_file and the script is gathering the data for that particular servers. But when it comes to other servers its fails.

        From looking through the Net::SSH::Perl documentation, I see no way of adding a host to the known identities. I recommend you get the list of trusted servers and their fingerprints from your system administrators.

Re: Failed to connect the server using Net::SSH::Perl
by Khen1950fx (Canon) on Apr 20, 2010 at 00:19 UTC
    Without the code, it's impossible to find the error. Try this to debug it:
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper::Concise; use Net::SSH::Perl; my $host = 'host'; my $user = 'user'; my $pass = 'password'; my $ssh = Net::SSH::Perl->new( $host, debug => 1, protocol => 2,1 ); $ssh->login($user, $pass); $ssh->session_id; $ssh->config; print Dumper $ssh; exit;