Skip to content

Instantly share code, notes, and snippets.

@Genki-S
Last active January 8, 2020 05:20
Show Gist options
  • Save Genki-S/88349f3b8a3c150097741ed9ee1a994f to your computer and use it in GitHub Desktop.
Save Genki-S/88349f3b8a3c150097741ed9ee1a994f to your computer and use it in GitHub Desktop.
Automatically start ssh-agent when necessary, and kill ssh-agent when ssh is done (to not leave many ssh-agent processes around)
ssh() {
if [ -z "$SSH_AGENT_PID" ]; then
eval "$(ssh-agent -s)"
# ssh-add OTHER_KEYS
fi
command ssh $@
kill $SSH_AGENT_PID
unset SSH_AGENT_PID
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment