Quoting RFC4254 § 6.6. Session Data Transfer,

Data transfer for a session is done using SSH_MSG_CHANNEL_DATA and SSH_MSG_CHANNEL_EXTENDED_DATA packets and the window mechanism. The extended data type SSH_EXTENDED_DATA_STDERR has been defined for stderr data.

My question is... why, when I do ls -latr 1>&2 && pwd, via an interactive shell in PuTTY, am I not seeing any SSH_MSG_CHANNEL_EXTENDED_DATA packets? Here's my PuTTY logs:


It also doesn't work if I set "Connection -> SSH -> Remote command" to ls -latr 1>&2 && pwd:


It DOES, however, work fine if I set "Connection -> SSH -> Remote command" to ls -latr 1>&2 && pwd and if I check "SSH -> TTY -> Don't allocate a pseudo-terminal":


Basically, it seems that the use of a TTY precludes the sending of SSH_MSG_CHANNEL_EXTENDED_DATA.



For an interactive session, the remote SSH server will allocate a PTY (pseudo-TTY). Then it will invoke the user's shell with the PTY as the standard input, output and error. Output written to standard output and standard error end up written to the same PTY and mixed into a single data stream. The SSH server reads the output being written to the PTY and sends it to the client. The SSH server doesn't separate the data written to stdout from the data written to stderr, and I don't know if there's even a way that it could.

It's the same behavior that you get when you run a command in a terminal:

$ ls /etc/group /etc/does-not-exist
ls: /etc/does-not-exist: No such file or directory

ls wrote some data to standard output and some to standard error. All of it appeared mixed together in the terminal. The only way to identify which was which is by knowing how ls works and how unix commands are generally supposed to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.