When running the same ssh command with -T and -t, any stderr output arrives on stderr vs. stdout, respectively.
No pty allocated:
ssh -T user@host "echo >&2 foo" 1>/tmp/out 2>/tmp/err
Output is written to /tmp/err
.
With pty allocation: ssh -t user@host "echo >&2 foo" 1>/tmp/out 2>/tmp/err
Output is now written to /tmp/out
.
I somewhat understand that with pty a full pseudo screen is simulated and that the output is in raw mode. The output sent to the screen then are sent via stdout back to ssh and ssh's tty is also set to raw mode. Can somebody please explain it further?