2

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.