Skip to content

Instantly share code, notes, and snippets.

@piaverous
Last active July 12, 2024 00:31
Show Gist options
  • Save piaverous/94c0c3b03014a36eb05b6cced17e77c1 to your computer and use it in GitHub Desktop.
Save piaverous/94c0c3b03014a36eb05b6cced17e77c1 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