Last active
January 13, 2017 10:13
-
-
Save jolbax/c1af7d0409b3086730dde129864042a5 to your computer and use it in GitHub Desktop.
Using an ssh-agent in a script
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/bash | |
tempfile=/tmp/ssh-agent.test | |
#Check for an existing ssh-agent | |
if [ -e $tempfile ] | |
then | |
echo "Examining old ssh-agent" | |
. $tempfile | |
fi | |
#See if the agent is still working | |
ssh-add -l > /dev/null | |
#If it's not working yet, just start a new one. | |
if [ $? != 0 ] | |
then | |
echo "Old ssh-agent is dead..creating new agent." | |
#Create a new ssh-agent if needed | |
ssh-agent -s > $tempfile | |
. $tempfile | |
#Add the key | |
ssh-add | |
fi | |
#Show the user which keys are being used. | |
ssh-add -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment