[sf-lug] how to get a program (e.g. shell script) to log in: e.g. respond to the password prompt?

Usr Bin Sh usr.bin.sh at gmail.com
Sat Aug 23 18:11:13 PDT 2008

In bash you can use (and such sequence works for telnet, ftp):

(sleep ${tout}; echo ${theuser}; sleep ${tout}; echo ${pword}; sleep
${tout}; echo "pwd"; sleep ${tout}; echo "exit") | telnet

it doesn't work for ssh/scp, but may work for some legacy
applications. And yes, as previously was noted:using ssh/scp with
passwordless key is preferable.
Search google "ssh passwordless key"
e.g. this link has nice description:

> Message: 2
> Date: Sat, 23 Aug 2008 08:28:24 -0700
> From: Michael Paoli <Michael.Paoli at cal.berkeley.edu>
> Subject: [sf-lug] how to get a program (e.g. shell script) to log in: e.g.    respond to the password prompt?
> To: sf-lug at linuxmafia.com
> Message-ID: <1219505304.48b02c9837a72 at webmail.rawbw.com>
> Content-Type: text/plain; charset=ISO-8859-1
>> Date: Fri, 22 Aug 2008 10:03:06 -0700
>> From: Rick Moen <rick at linuxmafia.com>
>> Subject: Re: [sf-lug] perl backup script, and other perl goodies
>> To: sf-lug at linuxmafia.com
>> Quoting Asheesh Laroia (asheesh at asheesh.org):
>> > On Fri, 22 Aug 2008, jim wrote:
>> > >   how to get a program (shell script most likely
>> > > in my case) to log in: i.e. issue a
>> > > scp <file> <user>@<host>:<dir>
>> > > command and then respond to the password prompt?
>> > Public key authentication.  See http://apt-get.dk/howto/backup/.
>> I have more about that technique here:  "SSH Public-Key Process" on
>> http://linuxmafia.com/kb/Security/
> Yes, public key authentication would typically be the preferred method.
> One would typically want to have the private key well secured and
> protected, including being encrypted with a strong passphrase - at least
> if that latter part is feasible for the intended usage.
> Another possible approach is expect.  Some other languages, etc. (e.g.
> perl, tk), and also some utilities/programs (such as those originally
> designed for serial communications, such as some uucp and ppp software)
> also have expect modules or the equivalent, or expect or expect-like
> capabilities.  The disadvantage with the expect type approach, is that
> one must somehow get expect to issue the clear text password in response
> to the password prompt (at least if that's how one is going to
> authenticate).
> references:
> ssh(1)
> ssh-keygen(1)
> ssh-agent(1)
> expect(1)
> perl(1)
> http://www.cpan.org/
> apt-cache(1) (as in apt-cache search ...)
> ...

More information about the sf-lug mailing list