Linux – Why can I see password prompts through redirecting output

linuxredirectionsshstderrstdout

So, I've got a command that I'm issuing that is essentially 'ssh'ing into various hosts:

 command 2&>1 | grep "desired output" 

Every once in a while, in the midst of the command, it'll run into a host where I don't have my keys setup. When that happens, I get this output:

 Password: 

Since I'm redirecting STDERR into STDOUT, then filtering STDOUT to only give me "desired output" (which doesn't include "Password:"), how is the password prompt being presented to me?

Best Answer

ssh opens /dev/tty for read and write to prompt for the password.

I guess this a security feature, the input has to be from the tty rather than stdin.

If you run strace ssh <host> strace will show you the system calls the command is making.

I get:

open("/dev/tty", O_RDWR|O_LARGEFILE)    = 4
...
write(4, "dave@host"..., 16dave's password: ) = 16
read(4,
Related Question