[sudo-users] Why sudo(1) asks for password when stdout and stderr are redirected?
Todd C. Miller
Todd.Miller at courtesan.com
Tue Aug 9 08:36:48 EDT 2011
Sudo writes the password prompt to and reads the password from /dev/tty
when it is available. This allows things like:
$ sudo grep foo /some/file > output
to work properly without the prompt getting mixed up in the output.
If you don't want sudo to prompt for a password you can use the
-n (non-interactive) flag. Of course, this will cause sudo to fail if it
needs to read the password. If what you really want is to prevent
sudo from asking for the password, you can either use the NOPASSWD
tag on the command in sudoers or disable authentication entirely.
See the sudoers manual for more information.
More information about the sudo-users