Created
October 19, 2016 11:53
-
-
Save mcustiel/d3dd1f9a4f9a8965f98957348d92a9ad to your computer and use it in GitHub Desktop.
Start ssh agent if it is not running
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
# If ssh-agent is not running, start it and add all keys | |
LINES=$(ps aux | grep ssh-agent | wc -l) | |
PPKDIR=~/.ssh/keys | |
PATTERN="\\.pub$" | |
if [ "2" -gt $LINES ] ; then | |
ssh-agent -s > ~/.ssh-env-vars | |
. ~/.ssh-env-vars | |
for key in $(ls $PPKDIR) ; do | |
# Add only private keys to ssh-agent | |
if [[ ! $key =~ $PATTERN ]]; then | |
ssh-add $PPKDIR/$key | |
fi | |
done | |
else | |
. ~/.ssh-env-vars | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment