#!/usr/bin/env perl use warnings; use strict; use Net::SSH2 ':all'; use Config; my $host = 'REDACTED'; my $username = 'REDACTED'; my $password = 'REDACTED'; print STDERR "__DATA__\n\n__RESULTS__\n"; print STDERR "\$] => $]\n"; print STDERR "$_ => $Config{$_}\n" for qw/archname osname osvers/; print STDERR "\n\nhost at \$work\n"; my $ssh2 = Net::SSH2->new(); my $rv = $ssh2->connect($host) or $ssh2->die_with_error; print STDERR "\tconnect => $rv\n"; #$rv = $ssh2->check_hostkey(LIBSSH2_HOSTKEY_POLICY_ASK) or $ssh2->die_with_error; print STDERR "\tcheck hostkey => $rv\n"; # yes, I know I should... but not doing this for now; you had trouble, too... and I trust this local host $rv = $ssh2->auth_list($username) or $ssh2->die_with_error; print STDERR "\tauth_list => $rv\n"; $rv = $ssh2->auth_password($username, $password) or $ssh2->die_with_error; print STDERR "\tauth_password => $rv\n"; my $chan = $ssh2->channel() or $ssh2->die_with_error; print STDERR "\tget channel => $rv\n"; $rv = $chan->exec('ls -l') or $ssh2->die_with_error; print STDERR "\texec ls => $rv\n"; print STDERR "line read: " . $chan->readline(); $rv = $chan->close() or $ssh2->die_with_error; print STDERR "\tchan close => $rv\n"; $rv = $ssh2->disconnect() or $ssh2->die_with_error; print STDERR "\tdisconnect => $rv\n"; print STDERR "\n\nshell02.theworld.com:\n"; $ssh2 = Net::SSH2->new(); $ssh2->connect('shell02.theworld.com') or $ssh2->die_with_error; $rv = $ssh2->auth_list() or $ssh2->die_with_error; print STDERR "\tauth_list => $rv\n"; $rv = $ssh2->auth_password_interact($username) or $ssh2->die_with_error; print STDERR "\tauth_password_interact => $rv\n"; # this wouldn't work on my strawberry perl: "Non-blocking ReadLine is not supported on this architecture" __DATA__ __RESULTS__ $] => 5.026002 archname => MSWin32-x64-multi-thread osname => MSWin32 osvers => 10.0.16299.371 host at $work connect => 1 auth_list => publickey,gssapi-with-mic,password auth_password => 1 get channel => 1 exec ls => 1 line read: total 948 chan close => 1 disconnect => 1 shell02.theworld.com: auth_list => publickey,keyboard-interactive REDACTED's password? Non-blocking ReadLine is not supported on this architecture at C:/usr/local/apps/berrybrew/perls/5.26.2_64_PDL/perl/vendor/lib/Net/SSH2.pm line 314.