Subject: Re: ssh expect on Cygwin
From: Brian Dessent <[email-masked]>
To: [email-masked]
Date: Wed, 20 Oct 2004 10:48:37 -0700

anurag shukla wrote:

> Hi,
> I just got your mail id from the Cygwin MAiling list.

You're posting to the list, not sending email to any specific person. 
Most people who post on the list do not want to receive email with
questions.  That's what the list is for.

> I am having a tyical problem with expect.
> This is the code fragment that is giving me the problem. May be you
> can help me with this conundrum
> #!/usr/bin/expect
>    spawn ssh -l $user $box_ip
> 
>    while {1} {
>        expect {
>            -exact "$user@$box_ip's password: " {
>              send -- "$passwd\n"
>              break;
>            }
> 
> The problem is every time I run the script, it asks me for the
> password, though it should not. Also, when prompted for password, when
> I enter the password, it just does not accepts it.
> I am running Cygwin on WIndows XP.

I believe that ssh tries to read the passphrase directly from the
terminal from which it was started, rather than reading stdin.  This
allows it to ask for a password even if stdin has been redirected, as in
the case of running a remote command with input.  So, you can't feed it
a password like that with expect.

But, seeing someone try to feed ssh a password with expect will make
most people cringe because "that's not the right way to do it."  You
should instead use public key authentication which allows for secure and
passwordless authentication to the remote system.  All you need to do is
generate a key (run ssh-host-config on the local Cygwin system) and then
place the public half of the key (id_rsa.pub if you chose RSA) in
~/.ssh/authorized_keys on the remote.  Read "man ssh" and "man
ssh_config" for details.

If you *really* must feed ssh a password (despite completely missing the
entire reason for having public key authentication) then look at the
SSH_ASKPASS variable which is documented in the manpage.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/