Last active
August 21, 2023 19:31
-
-
Save ryancurrah/f4fb629905360a2ab6abbf543bbabfb8 to your computer and use it in GitHub Desktop.
ssh-agent
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
#!/bin/zsh | |
# Check for a currently running instance of ssh-agent | |
RUNNING_AGENT="$(ps -ax | grep 'ssh-agent' | grep -v grep | wc -l | tr -d '[:space:]')" | |
if [ "${RUNNING_AGENT}" = "0" ]; then | |
# Launch a new instance of ssh-agent | |
eval "$(ssh-agent)" | |
else | |
# Connect to the existing ssh-agent instance | |
export SSH_AUTH_SOCK="$(find /var/folders/*/*/*/ssh-* -name 'agent.*' -user "$(whoami)" 2> /dev/null | head -n 1)" | |
fi | |
# Check that ssh keys are loaded | |
ssh-add -l > /dev/null | |
if [ "${?}" != "0" ]; then | |
# No ssh keys are loaded; add the default key | |
ssh-add -q --apple-load-keychain | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment