Why does OpenSSH RequestTTY cause stderr redirected to stdout? Why does OpenSSH RequestTTY cause stderr redirected to stdout? unix unix

Why does OpenSSH RequestTTY cause stderr redirected to stdout?


A tty does not have separate output and error channels. There is only one output channel; whatever you write to it simply goes to the CRT, serial port, terminal window, modem, printer, or whatever is connected to the tty.

When allocating a tty for running a command, ssh could in theory attach the command's stdin and stdout to the tty, while in contrast attaching the command's stderr to a separate stderr channel (a pipe) that is completely separate from the tty. However, this does not agree with the convention that a command running on a tty should have all 3 of its stdio channels connected to that same tty, and some commands might be confused or behave differently. So ssh chooses to follow convention.

When not using a tty, ssh is free to attach the command's stdin, stdout, and stderr to 3 separate unidirectional pipes.