Forum Discussion

SujeetKP_313828's avatar
Icon for Nimbostratus rankNimbostratus
Mar 15, 2017

Unable to SSH using Perl

hi All,


I am trying to connect to F5 load balancer through perl module Net::SSH2. "connect" method is working but I am unable to authenticate, whereas with the same credentials I am able to ssh to the device through putty. Can somebody please help me with this.




use strict;
use Net::SSH2;

my $ssh=Net::SSH2->new();
 print "successfully connected";
$ssh->auth_password('username','password') or $ssh->die_with_error;



Authentication failed (username/password) (-18 LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED) at line 8.
successfully connected

1 Reply

  • Artur_Zdolinsk1's avatar
    Historic F5 Account
    • $ssh->auth_password('username','password') or $ssh->die_with_error;
    • $ssh->auth(username => 'username', password => 'password') or $ssh->die_with_error;
    use Net::SSH2;
    $host = "";
    $user = "root";
    $pass = "default";
    my $ssh2 = Net::SSH2->new();
    $ssh2->connect($host) or die $!;
    $ssh2->auth(username => $user, password => $pass) or die "Unable to login \n".$ssh2->die_with_error;
    print "Connected to '$host' as '$user' \n";
    my $chan = $ssh2->channel();
     Read remote controller program header
     close channel and disconnect
     read_chan: read all input from chan, dump it to STDOUT
    sub read_chan {
      my ($chan) = @_;
       we switch to non-blocking and sleep between retries because it
       would fail to read anything with a blocking call... Still trying
       to find out why the blocking call would not read nothing.
      my $done;
      while (1) {
        my $in;
        while (my $bytes = $chan->read($in, 1024)) {
          $in =~ s/^/> /gm;
          print $in;
         We leave after one sucessful read, this could be improved...
        last if $done;
        select(undef, undef, undef, .25);  sleep 50 ms


    root@Linux200:~ perl
    Connected to '' as 'root'
    >  16:24:56 up  6:37,  1 user,  load average: 0.00, 0.01, 0.00

    Debian / perl 5.24.1