Skip to content

Instantly share code, notes, and snippets.

@hussainweb
Created June 12, 2015 16:22
Show Gist options
  • Save hussainweb/079fc504873057050c19 to your computer and use it in GitHub Desktop.
Save hussainweb/079fc504873057050c19 to your computer and use it in GitHub Desktop.
Bash Profile script to setup ssh agent so that operations such as ssh and git don't ask for a password to decrypt public keys every time.
# Paste in ~/.bash_profile
#
# Load ssh-agent. Taken from
# http://blog.killtheradio.net/how-tos/ssh-agent-on-cygwin/
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
eval `$SSHAGENT $SSHAGENTARGS`
trap "kill $SSH_AGENT_PID" 0
fi
# ssh become a function, adding identity to agent when needed
ssh() {
if ! ssh-add -l >/dev/null 2>&-; then
ssh-add ~/.ssh/id_rsa
fi
/usr/bin/ssh "$@"
}
export -f ssh
# another example: git
git() {
if ! ssh-add -l >/dev/null 2>&-; then
ssh-add ~/.ssh/id_rsa
fi
/usr/bin/git "$@"
}
export -f git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment