Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save toddlers/55b3cd2824d6f30b627a4bce242206b9 to your computer and use it in GitHub Desktop.
Save toddlers/55b3cd2824d6f30b627a4bce242206b9 to your computer and use it in GitHub Desktop.
A simple bash snippet to add to your .bashrc or .zshrc in order to easily load password protected SSH Keys from the Apple Keychain, and never worry about them again !
###
# SSH keys setup with Apple keychain
###
if [ -z "$SSH_AUTH_SOCK" ] && [ -z "$SSH_AGENT_PID" ]; then
# If no SSH Agent is running, start one and load keys from Apple keychain
eval `ssh-agent -s` &> /dev/null
ssh-add --apple-load-keychain &> /dev/null
else
if [ -z "$(ssh-add -l | grep SHA256)" ]; then
# If agent is running but has no keys, load keys from Apple keychain
ssh-add --apple-load-keychain &> /dev/null
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment