Forked from piaverous/setup_ssh_agent_with_apple_keychain.sh
Created
March 16, 2022 08:49
-
-
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 !
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
### | |
# 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