Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash snippets to automatically start and stop an ssh-agent process on login and logout
#!/bin/bash
## in .bash_profile
SSHAGENT=`which ssh-agent`
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
eval `$SSHAGENT $SSHAGENTARGS`
trap "kill $SSH_AGENT_PID" 0
fi
## in .logout
if [ ${SSH_AGENT_PID+1} == 1 ]; then
ssh-add -D
ssh-agent -k > /dev/null 2>&1
unset SSH_AGENT_PID
unset SSH_AUTH_SOCK
fi
@avramd

This comment has been minimized.

Show comment
Hide comment
@avramd

avramd Aug 11, 2014

This is great, thanks!

avramd commented Aug 11, 2014

This is great, thanks!

@mCzolko

This comment has been minimized.

Show comment
Hide comment
@mCzolko

mCzolko Aug 7, 2018

Thank you!

mCzolko commented Aug 7, 2018

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment