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

Discussion in 'Perl Misc' started by cyrusgreats@gmail.com, Oct 26, 2007.

  1. Guest

    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
     
    , Oct 26, 2007
    #1
    1. Advertising

  2. all mail refused, Oct 26, 2007
    #2
    1. Advertising

  3. Re: How to interactively sending the username/password to login usingssh

    wrote:
    > 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
    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html
     
    Josef Moellers, Oct 26, 2007
    #3
  4. Guest

    On Oct 25, 5:05 pm, all mail refused <>
    wrote:
    > On 2007-10-25, <> wrote:
    >
    > > I'm trying to interactively sending the username/password to login and

    >
    > passwordless logins are in the SSH docs and FAQ
    > http://www.snailbook.com/faq/
    >
    > "expect" deals with terminal input if you really need
    > to provide a password that way. Various CPAN modules
    > involve it.
    > http://search.cpan.org/search?query=expect&mode=module
    >
    > --
    > Elvis Notargiacomo master AT barefaced DOT cheekhttp://www.notatla.org.uk/goen/


    Thanks to you all I got it now.
     
    , Oct 26, 2007
    #4
  5. On Oct 26, 9:08 am, wrote:
    > On Oct 25, 5:05 pm, all mail refused <>
    > wrote:
    >
    > > On 2007-10-25, <> wrote:

    >
    > > > I'm trying to interactively sending the username/password to login and

    >
    > > passwordless logins are in the SSH docs and FAQ
    > > http://www.snailbook.com/faq/

    >
    > > "expect" deals with terminal input if you really need
    > > to provide a password that way. Various CPAN modules
    > > involve it.
    > > http://search.cpan.org/search?query=expect&mode=module

    >
    > > --
    > > Elvis Notargiacomo master AT barefaced DOT cheekhttp://www.notatla.org.uk/goen/

    >
    > Thanks to you all I got it now.


    Why not use Net::SSH::perl module?

    Praveen Kandala
     
    praveen kandala, Oct 27, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arjen
    Replies:
    2
    Views:
    4,242
    Joe Fallon
    Apr 18, 2004
  2. Amit
    Replies:
    8
    Views:
    27,381
    Priyank
    Oct 13, 2011
  3. terminus
    Replies:
    0
    Views:
    421
    terminus
    Feb 26, 2008
  4. KDawg44
    Replies:
    2
    Views:
    238
  5. Guillermo Riojas
    Replies:
    0
    Views:
    184
    Guillermo Riojas
    Nov 26, 2010
Loading...

Share This Page