Last active
July 12, 2024 00:31
-
-
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 !
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