Last active
February 17, 2020 15:17
-
-
Save gubatron/2f457d4d7cc2b21272824a7805382cdb to your computer and use it in GitHub Desktop.
startSSHAgent bash function - checks for SSH_AGENT_PID in env, then for ssh-agent PID (pgrep), if not found, starts new ssh-agent, adds your keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
startSSHAgent() { | |
if [[ -z "$SSH_AGENT_PID" ]]; then | |
if [[ $(pgrep ssh-agent) ]]; then | |
export SSH_AGENT_PID=$(pgrep ssh-agent) | |
echo "Found existing ssh-agent PID, SSH_AGENT_PID=${SSH_AGENT_PID}" | |
else | |
echo "Starting fresh ssh agent" | |
eval `ssh-agent` | |
fi | |
fi | |
ssh-add ~/.ssh/my-private-key1 | |
ssh-add ~/.ssh/my-private-key2 | |
#... | |
ssh-add ~/.ssh/my-private-keyN | |
kill_old_ssh_agents #see https://gist.github.com/gubatron/2d97b31b0621c459f8b5ee8665c9f7b9 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
well I only eval if I can't find an existing ssh-agent, otherwise yes you end up with a bunch of ssh-agent processes
Ill check what's up with flowee.org and how I can help once I get a breather