Skip to content

Instantly share code, notes, and snippets.

@flannon
Last active October 5, 2017 20:56
Show Gist options
  • Save flannon/7a7e448fbc7acf2965732dbfcf550c4c to your computer and use it in GitHub Desktop.
Save flannon/7a7e448fbc7acf2965732dbfcf550c4c to your computer and use it in GitHub Desktop.
# start ssh-agent and load keys
SSH_AGENT=$(which ssh-agent)
SSH_AGENT_ARGS='-s'
# SSH_KEYS is a space separated list of ssh keys to load
SSH_KEYS='< -- your keys go here -->'
SSH_ADD=$(which ssh-add)
if [[ -z $SSH_AUTH_SOC && $SSH_AGENT ]]; then
eval $($SSH_AGENT $SSH_AGENT_ARGS) 2>&1 1>/dev/null
for i in $SSH_KEYS; do
$(echo $SSH_ADD) -k $HOME/.ssh/$i 2>&1 1&>/dev/null
done
# trap on sig 0 runs command on exit
# do $SSH_AGENT will die on logout
trap "kill $SSH_AGENT_PID" 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment