I'm trying to troubleshoot a sudden outbreak of short-lived SSH connections. These connections are initiated from my Mac (MBP, Catalina 10.15.6, zsh
) to some of the Linux "appliances" that live on my network here - in particular the Raspberry Pies. After the connections terminate, they leave the message client_loop: send disconnect: Broken pipe
in the terminal.
However: That's offered only as background in case it's related to my immediate question:
Why does the command ssh-agent -k
not kill ssh-agent
?
It appears to fail because the environment variable SSH_AGENT_PID
is not set. I have guessed that based on what I see in my Mac terminal app:
1. list ssh-related processes:
% pgrep -f ssh
2138
75076
75942
75943
75944
% ps 2138
PID TT STAT TIME COMMAND
2138 ?? S 0:00.26 /usr/bin/ssh-agent -l
PID 2138
is ssh-agent
, the other PIDs are active ssh
connections to Raspberries or Ubuntu box - all Linux.
2. kill ssh-agent
IAW man ssh-agent
:
From man ssh-agent
:
ssh-agent [-c | -s] -k
-k Kill the current agent (given by the SSH_AGENT_PID environment variable).
% ssh-agent -k
SSH_AGENT_PID not set, cannot kill agent
% sudo ssh-agent -k
SSH_AGENT_PID not set, cannot kill agent
% echo $SSH_AGENT_PID
%
I can kill ssh-agent
using kill 2138
, or with pkill ssh-agent
, and so it seems that perhaps the answer is Apple's version of ssh-agent
doesn't provision the environment variable SSH_AGENT_PID
. But if that's the answer, it raises another question: Is there a valid reason for not assigning the environment variable SSH_AGENT_PID
?
Also note that a related question. However, the OP for that question didn't identify his SSH client host was macOS. He also indicated SSH_AGENT_PID
was not set, but seemed concerned only with how ssh-agent
was started. In my case (macOS), ssh-agent
is started when an ssh connection is initiated. I found other Q&A in the "Similar Questions" suggestion box; I read a few of them, but none seem the same as mine.