Looking for Net::SSH2 authentication with interactive screen. Perl

339 Views Asked by At

I am trying to access shell of a remote unix node. I need to go through its login process.

Step 1 : The login screen requires me to type 'start' after which below screen appears I need to select the last option to go to password prompt

Step 2: To get the password prompt, I need to press 'down arrow key' twice and then press enter. i.e. Select 'Console Terminal Access' option.

I am implementing this with Perl Net::SSH2 Module.

I need to use either 'auth' method or 'auth_password_interact' method. I am facing difficulties in implementing the callback section. Where the above explained login process can be handled and it sends the password at the password prompt

I have tried below code, can anyone help me on how the interactive section can be implemented here.

#!/usr/bin/perl
use strict;
use warnings;
use Net::SSH2;
use Term::ReadKey;

my $ssh2 = Net::SSH2->new();
$ssh2->connect('10.24.7.174'); # Connection is successful here

print $ssh2->auth_list(); # prints Publickey keyboard-interactive
$| =1; # Flush output to see characters pressed
# I assume this mode is used for 'menu-selection' type actions
ReadMode 'cbreak';

'Need Help here'

sub loginNode{
    ## Need to read 2 arrow keys and then Enter ( carriage Return )
    my $char = ReadKey 0; # Read until carriage return is pressed
}

#$ssh2->auth_password_interact('start',&loginNode);
$ssh2->auth(  'username' => 'start',
          'password' => '*****',
          'interact' => 1,
          'keyboard-auto' => 1,
          'callback' => &loginNode());

#my $chan = $ssh2->channel(); # This fails, as authentication fails
#$chan->exec('ls -al');
END {
   ReadMode('restore');# option 0
}

I couldn't find any examples of such implementation anywhere.

0

There are 0 best solutions below