Forum Discussion
SujeetKP_313828
Mar 15, 2017Nimbostratus
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 t...
Artur_Zdolinsk1
Sep 07, 2018Historic F5 Account
- $ssh->auth_password('username','password') or $ssh->die_with_error;
- $ssh->auth(username => 'username', password => 'password') or $ssh->die_with_error;
!/usr/bin/perl
use Net::SSH2;
$host = "192.168.254.10";
$user = "root";
$pass = "default";
my $ssh2 = Net::SSH2->new();
$ssh2->debug(1);
$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();
$chan->exec('uptime');
Read remote controller program header
read_chan($chan);
close channel and disconnect
$chan->close;
$ssh2->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.
$chan->blocking(0);
my $done;
while (1) {
my $in;
while (my $bytes = $chan->read($in, 1024)) {
$in =~ s/^/> /gm;
print $in;
$done++;
}
We leave after one sucessful read, this could be improved...
last if $done;
select(undef, undef, undef, .25); sleep 50 ms
}
$chan->blocking(1);
}
Output:
root@Linux200:~ perl connect.pl
Connected to '192.168.254.10' as 'root'
> 16:24:56 up 6:37, 1 user, load average: 0.00, 0.01, 0.00
Debian / perl 5.24.1
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects