capture SSH warning message in a variable

I’m trying capture the ssh output in a variable. But it’s ignoring the warning message and capturing everything else. Requirement: x=$(ssh -o PasswordAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no [email protected]$(hostname) echo 2>&1) echo $x Warning: Permanently added ‘<host>’ (RSA) to the list of known hosts. Permission denied (gssapi-with-mic,password). Observation echo $x Permission denied (gssapi-with-mic,password). The warning message…

Details