Skip to Content
Linux Security Cookbook
book

Linux Security Cookbook

by Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
June 2003
Intermediate to advanced
336 pages
8h 54m
English
O'Reilly Media, Inc.
Content preview from Linux Security Cookbook

6.11. Terminating an SSH Agent on Logout

Problem

When you log out, you want the ssh-agent process to be terminated 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 invoke yourself don’t die automatically when you log out: you must kill them explicitly. When you run an agent, it defines the environment variable SSH_AGENT_PID. [Recipe 6.9] Simply test for its existence and kill the agent with the -k option.

See Also

ssh-agent(1).

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Linux Security Cookbook - Second Edition

Practical Linux Security Cookbook - Second Edition

Tajinder Kalsi
Mastering Linux Command Line

Mastering Linux Command Line

Coding Gears | Train Your Brain

Publisher Resources

ISBN: 0596003919Errata Page