How to interactively sending the username/password to login using ssh

C

cyrusgreats

Hi ,
I'm trying to interactively sending the username/password to login and
then send CLI commands usinf ssh, this is the only way I can access
the device, and then sending the commands when logged in, I used the
following but it seems does not pass the password, I'm sure one of you
guyus out there have an idea. Thanks in advance..


#!/usr/bin/perl

use IPC::Session;

# open ssh session to your applinace
# -- set timeout of 30 seconds for all send() calls
my $mybox = "10.0.42.111";
my $session = new IPC::Session("ssh -l usrname $mybox",30);

# use like 'expect':
print $session->send("passwd");


Here I see the Password prompt but I can't pass password ..
cheers
 
J

Josef Moellers

Hi ,
I'm trying to interactively sending the username/password to login and
then send CLI commands usinf ssh, this is the only way I can access
the device, and then sending the commands when logged in, I used the
following but it seems does not pass the password, I'm sure one of you
guyus out there have an idea. Thanks in advance..


#!/usr/bin/perl

use IPC::Session;

# open ssh session to your applinace
# -- set timeout of 30 seconds for all send() calls
my $mybox = "10.0.42.111";
my $session = new IPC::Session("ssh -l usrname $mybox",30);

# use like 'expect':
print $session->send("passwd");


Here I see the Password prompt but I can't pass password ..
cheers

I don't see anything about ttys in IPC::Session's pod. Therefore I
assume that it just spawns off an ssh with a pipe opened between the
script and the ssh (I don't have it installed, so I can't check, but you
can check using some system call trace command, e.g. strace. Beware that
you must tell strace to follow subprocesses!). For some (security?)
reasons, on Linux ssh will open /dev/tty to obtain the password, so you
can't send it through the pipe.

It would be better, indeed, to use the Expect module to handle this. On
Linux, Expect will communicate with the subprocess through a pseudo tty,
which is set up as the subprocess' controlling tty and, as such, will be
accessable through /dev/tty.

Josef
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top