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.
When there's no better choice (as suggested by others), then man socat can help:
All of the pty,setsid,ctty complexity is necessary and, while you might not need to sleep as long, you will need to sleep. The echo=0 option is worth a look too, as is passing the remote command on ssh's command line.
I had the same problem. dialog script to create directory on remote pc. dialog with ssh is easy. I use sshpass (previously installed).
greetings from germany
titus
Hope it is helpful.
I've got:
Works for me.
For sudo you can do this too:
Hardcoding a password in an expect script is the same as having a passwordless sudo, actually worse, since sudo at least logs its commands.