Created
June 27, 2022 12:37
-
-
Save mkhon/ff695e50b29cd3a369c69d38cd5c7a4c to your computer and use it in GitHub Desktop.
Find existing ssh-agent or start new
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/sh | |
SSH_AUTH_SOCK= | |
for f in `ls /tmp/ssh-*/agent.*`; do | |
if SSH_AUTH_SOCK=$f ssh-add -l >/dev/null 2>&1; then | |
SSH_AUTH_SOCK=$f | |
echo "Found existing ssh agent SSH_AUTH_SOCK=$SSH_AUTH_SOCK" | |
break | |
fi | |
done | |
if [ -z "$SSH_AUTH_SOCK" ]; then | |
echo "Started new ssh agent SSH_AUTH_SOCK=$SSH_AUTH_SOCK" | |
eval `ssh-agent` | |
ssh-add | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment