Problem
When you logout, you want the ssh-agent process to beterminated automatically.
Solution
For bash:
~/.bash_profile:trap 'test -n "$SSH_AGENT_PID" && eval `/usr/bin/ssh-agent -k`' 0
For csh or tcsh:
~/.logout:if ( "$SSH_AGENT_PID" != "" ) then eval `/usr/bin/ssh-agent -k`endif
Discussion
SSH agents you invokeyourself don’t die automatically when you log out:you must kill them explicitly. When you run an agent, it defines theenvironment variable SSH_AGENT_PID
. [Recipe 6.9] Simply test for its existence and kill theagent with the -k option.
See Also
ssh-agent(1).
Get Linux Security Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.