2

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.

Kiran Chaudhary
  • 124
  • 1
  • 2
  • 7
  • Do you want to make the user of your program go through the motions to access the remote machine (as in your user presses keys on their local keyboard) or do you want to automate it? – simbabque Nov 18 '16 at 12:44
  • @simbabque I want to automate it. – Kiran Chaudhary Nov 21 '16 at 04:20
  • Please ignore this question, as later I realized, there were many technical things that was running in background which was allowing me to access the console of the system manually, it was not just simple SSH check. – Kiran Chaudhary Nov 29 '16 at 05:29

0 Answers0