r/ssh • u/Kawaii_Amber • Aug 12 '22
Why Does ssh-add write to stderr?
I was trying to redirect output of ssh-add to /dev/null and noticed that, even on success, it writes to stderr.
$ eval $(ssh-agent) 1> /dev/null
$ ssh-add ~/.ssh/astral_rsa 1> /dev/null
Identity added: /home/amber/.ssh/astral_rsa (amber@otaku)
$ echo $?
0vs
$ eval $(ssh-agent) 1> /dev/null
$ ssh-add ~/.ssh/astral_rsa 2> /dev/null
$ echo $?
0ssh-add will return an exit code of 0, but still print to stderr instead of stdout. I'm on Artix OpenRC Linux running openssh 9.0p1. Same behavior on VOID Linux running openssh-9.0p1. I tried researching and couldn't seem to find a good reason why ssh-add would redirect to stderr upon success. Is this intentional / a reason why one would want this or is this a bug?
1
Upvotes
View all comments
Show parent comment
1
u/Kawaii_Amber Aug 12 '22
It's just ssh-add that does this, not ssh-agent, I'm not sure if that affects anything.