Re: Control stdin/stdout of an other program.. How can I do that ?



I know that ssh keys exists.. I know about ssh_agent and all these
things..
But I'm limited in my environment and I won't be able to change
these things to put an ssh key everywhere.

What I want to do is connect to a list of servers via ssh (OpenSSH)
and only get prompted for the password once (assuming the password is
the same for all the servers).

How long are you prepared to wait for the password prompt *if there
isn't one*? (if, for example, you're using a RSA or DSA key to log in
on this host). Or can you be sure there always will be one? Or that
you will always know in advance whether there is one? Also, are you
sure the ssh password is requested on stdin, as opposed to /dev/tty?


I would like my program to start ssh, get the "password:" prompt and
then issue the password. Once this is done, leave the session to me.

If you are controlling both stdin and stdout of another process, beware
of deadlock. This especially goes in the "leave the session to me" part.
Suppose, for example, that you shove a dump command down the pipe, and
the remote host runs it. If that dump command produces too much output
and you don't read it, but are shoving another command down following it,
you could end up with both processes waiting on write.

Ways to avoid deadlock include (a) use separate processes to handle stdin
and stdout, (b) use non-blocking I/O and select() or poll(), or (c) use
a pty instead of a pipe.

Like if I could send keys to a system() call.
Actually, this thing will be used to issue commands to many servers
at the same time to do basic administration.. like creating a user on
many systems.

I've seen in the past some softwares reading/writing to the passwd
command.. for example P-Synch from MTechIT.. the problem is that I
haven't seen the source code and I'm having problems finding what I am
looking for with the stdin/stdout/read/write keywords..

Look for the program "expect".

Anyone can refer me to an open source application that do soemthing
similar or a basic script example.
.



Relevant Pages

  • Re: [opensuse] BASH - Need help with ssh remote directory test?
    ... $DESTHOST as a part of the environment. ... If D.C.R. had quoted the command correctly himself, ... The real reason why only the first host is tested is, that ssh "sucks" ... away all stdin so that the read in the while-loop sees only the first ...
    (SuSE)
  • Re: Rsync problem
    ... connecting to a remote host is wrong file/directory permissions on the ... The .ssh directory should have permissions 700 and the ... The above command essentially logs in via ssh, ... if it exists it then cats out the ssh key to the ...
    (Ubuntu)
  • Re: Rsync problem
    ... 3> ssh root@xxxxxxxxx address in *destination pc*. ... 4> After that when i use scp command in destination pc to source pc ... When creating your ssh key it prompts for an *optional* password. ...
    (Ubuntu)
  • Re: Rsync problem
    ... ssh " command then it is asking root password. ... connecting to a remote host is wrong file/directory permissions on the ... The above command essentially logs in via ssh, ... if it exists it then cats out the ssh key to the ...
    (Ubuntu)
  • Re: Rsync problem
    ... Also, just out of curiosity, did you set a password on your ssh key? ... When creating your ssh key it prompts for an *optional* password. ... connecting to a remote host is wrong file/directory permissions on the ... The above command essentially logs in via ssh, ...
    (Ubuntu)