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.
The usual solution to this problem is setuiding a helper app that performs the task requiring superuser access: http://en.wikipedia.org/wiki/Setuid
Sudo is not meant to be used offline.
Later edit: SSH can be used with private-public key authentication. If the private key does not have a passphrase, ssh can be used without prompting for a password.
Building on @Jahid's answer, this worked for me on macOS 10.13: