Liberat0r Liberat0r - 1 year ago 128
Linux Question

Pass a password to ssh in pure bash

I want to pass a password to

using a bash script (Yes, I know that there are ssh keys that I could use, but this is not what I intend).

I found some solutions that were using
but since it is not a standard bash tool I am wondering if I can do this using pipes.

Can someone explain to me, why exactly something like this:

echo "password\n" | ssh


ssh <(echo "password\n")

doesn't work? Is there any possibility to make it work? Maybe executing
as a different process, obtaining its PID and then sending a string directly to it?

Answer Source

Since there were no exact answers to my question, I made some investigation why my code doesn't work when there are other solutions that works, and decided to post what I found to complete the subject.
As it turns out:

"ssh uses direct TTY access to make sure that the password is indeed issued by an interactive keyboard user." sshpass manpage

which answers the question, why the pipes don't work in this case. The obvious solution was to create conditions so that ssh "thought" that it is run in the regular terminal and since it may be accomplished by simple posix functions, it is beyond what simple bash offers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download