by chasil · 3y ago · 0 comments
The "ssh-agent -k" command will emit shell commands that the shell must then execute which will kill the agent daemon and unset the socket environment variable.
$ ssh-agent
SSH_AUTH_SOCK=/var/folders/8p/_pwq997168s7vdwwdg_qr1j40000gn/T//ssh-DE0IoJfU5rrM/agent.15015; export SSH_AUTH_SOCK;
SSH_AGENT_PID=15016; export SSH_AGENT_PID;
echo Agent pid 15016;
$ SSH_AGENT_PID=15016; export SSH_AGENT_PID;
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 15016 killed;
That said, it doesn't hurt to eval it, so I overstated my case in my original comment.Does it really? I've executed it here and it just runs kill, doesn't emit any bash. Running just ssh-agent (without any args) does that though, which is what's probably causing the confusion.
$ eval $(ssh-agent)
Agent pid 56785
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 56785 killed;
The correct processing of that output requires an eval.Did you have any other questions?
$(ssh-agent)
won’t substitute that with the stdout and run that?
While redirecting to /dev/null will certainly work, the agent is holding sensitive credentials (by design), and confirmation of shutdown has a tangible security benefit.