Reputation: 2141
I'm writing a script to take a password and SSH with it. NOTE: I won't go into detail, but security/encryption is not an issue here--Hardcoded password is what I want. However, I'm having trouble piping it in so that the Unix script answers the "password:" prompt with it. I tried piping it in and it still asked me for the prompt.
I've seen answers on here that use expect...I'm not a shell scripting expert, when I tried it I got the errors spawn: command not found, interact: command not found, and send: command not found. I've tried googling some kind of expect to download and found nothing...what am I missing? this script should be distributable to people who may or may not have an external script installed.
My non-working code:
#!/bin/bash"
STR="MYPASS"
echo $STR | ssh -t -t user@host
Upvotes: 2
Views: 8101
Reputation: 22261
As per the answers you read, you need to use expect if you want to interact with ssh's password prompt. That is because SSH doesn't read the password from stdin (where you are piping it), it reads it from the tty.
If you were getting spawn: command not found
and interact: command not found
from your expect script, that's a clue that you wrote expect code into what was actually a shell script. Make sure the shebang line on your expect script actually contained #!/path/to/expect
and not #!/bin/sh
.
In any case, a much, much better idea would be to use SSH with public key authentication. A private key with no passphrase is easily scriptable and it no less secure than hardcoding a password into your script.
Upvotes: 3