Forum Discussion

Pallavi's avatar
Pallavi
Icon for Nimbostratus rankNimbostratus
Mar 02, 2020

Unable to SSH to F5 Loadbalancer via perl script

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 $1 from line number 16 but it lead to another error: Died at line 16

 

Also, in the development environment, I'm able to login to the device and fetch output via this script, but not in the client environment.

3 Replies

  • Hi,

    It code looks so simple to run :/

    Could you confirm that the user has terminal access as "Advanced shell" option?

     

    Regards.

  • Hello cjunior,

     

    I am able to manually login to the device using putty with same credentials but unable to login via this script. Also, The same script is working fine in development environment and is fetching output but in client environment its giving an error.

     

    Regards

  • Hi cjunior,

     

    Yes. The user has terminal access as "Advanced shell".