I'm writing a C Shell program that will be doing su
or sudo
or ssh
. They all want their passwords in console input (the TTY) rather than stdin or the command line.
Does anybody know a solution?
Setting up password-less sudo
is not an option.
expect could be an option, but it's not present on my stripped-down system.
For
ssh
you can usesshpass
:sshpass -p yourpassphrase ssh user@host
.You just need to download sshpass first :)
USE:
Example:
Hope It Helps..
Take a look at
expect
linux utility.It allows you to send output to stdio based on simple pattern matching on stdin.
I wrote some Applescript which prompts for a password via a dialog box and then builds a custom bash command, like this:
I'm not sure if this helps.
It'd be nice if sudo accepted a pre-encrypted password, so I could encrypt it within my script and not worry about echoing clear text passwords around. However this works for me and my situation.
One way would be to use read -s option .. this way the password characters are not echoed back to the screen. I wrote a small script for some use cases and you can see it in my blog: http://www.datauniv.com/blogs/2013/02/21/a-quick-little-expect-script/