Last active
August 29, 2015 14:16
-
-
Save carldanley/4905f8299dde0f996554 to your computer and use it in GitHub Desktop.
SSH Agent Scripts
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
# adds all keys in the ~/.ssh folder | |
function add_ssh_keys { | |
for i in `find ~/.ssh -name '*.pub' | sed 's/.\{4\}$//'`; | |
do ssh-add $i; | |
done | |
} | |
SSH_ENV=$HOME/.ssh/environment | |
function start_agent { | |
echo "Initializing new SSH agent..." | |
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" | |
chmod 600 "${SSH_ENV}" | |
. "${SSH_ENV}" > /dev/null | |
add_ssh_keys; | |
} | |
function stop_agent { | |
if [ ${SSH_AGENT_PID+1} == 1 ]; then | |
ssh-add -D | |
ssh-agent -k > /dev/null 2>&1 | |
unset SSH_AGENT_PID | |
unset SSH_AUTH_SOCK | |
fi | |
} | |
function restart_agent { | |
stop_agent; | |
start_agent; | |
} | |
if [ -f "${SSH_ENV}" ]; then | |
. "${SSH_ENV}" > /dev/null | |
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { | |
start_agent; | |
} | |
else | |
start_agent; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment