1

I am trying to connect to F5 load balancer through perl module Net::SSH2. I am unable to authentication error, whereas with the same credentials I am able to ssh to the device through putty. I have shared the Code and the error below for reference. Could somebody please help me with this.

use Net::SSH2; 
$deviceipF5 = "x.x.x.x";
$username = "xx";
$encrPass = "xx";


my @deviceipF5List = split(',',$deviceipF5);
if(@deviceipF5List ne 0)
    {
        foreach my $deviceipF5(@deviceipF5List)
        {
            my @deviceipF5List1 = split (':', $deviceipF5); 
            my $ssh2 = Net::SSH2->new();
            $ssh2->debug(0);
            $ssh2->connect($deviceipF5List1[0]) or die $!;
            $ssh2->auth(username => $username, password => $encrPass) or die "Unable to login \n".$ssh2->die_with_error;
            print "Connected to '$deviceipF5List1[0]' as '$username' \n";

            my $channel = $ssh2->channel() or do { print "Unable to create channnel ssh channel to Device $deviceipF5List[0]";$ssh2->disconnect(); last;};

            $channel->blocking(0);
            $channel->shell() ;
            print "SSH Success \n";
            sleep(2);

I have even tried to use auth_password instead of auth but no Luck.

Below is the error I am getting: Bad file descriptor at line 16

I tried removing $! from line number 16 but it lead to another error: Died at line 16

  • Is it displaying any error? – Pradeep Feb 28 '20 at 12:35
  • What specifically happens when you run your code? Do you get any error messages? What do the messages say? – Kenster Feb 28 '20 at 12:45
  • 1
    "Connect" is not working and the script is terminating at die. – pallavi singh Feb 29 '20 at 13:07
  • `Net::SSH2` does not use `$!` for reporting errors but its own [`error`](https://metacpan.org/pod/Net::SSH2#error) method. Call it after `connect` and tell us what it says. See also [error handling](https://metacpan.org/pod/Net::SSH2#Error-handling). – salva Mar 03 '20 at 07:33
  • 1
    Hello Salva, I tried using this solution. I got the below error: Unable to exchange encryption keys (-5 LIBSSH2_ERROR_KEX_FAILURE) at line 17 – pallavi singh Mar 04 '20 at 10:23
  • @pallavisingh, you may be using an old version of Net::SSH2/libssh2 without support for the modern encryption algorithms required by the remote host. `Net::SSH2->version` would tell you witch version is installed. – salva Mar 04 '20 at 17:26

0 Answers0