Last active
January 22, 2020 23:34
-
-
Save j1cs/c0d6107218b6af9c7252bf54f939a322 to your computer and use it in GitHub Desktop.
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
SSH_ENV=$HOME/.ssh/environment | |
function start_agent { | |
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"; | |
chmod 600 "${SSH_ENV}" | |
. "${SSH_ENV}" > /dev/null | |
adding_keys | |
} | |
function adding_keys { | |
for possiblekey in ${HOME}/.ssh/*; do | |
if grep -q PRIVATE "$possiblekey"; then | |
ssh-add -l | grep -q `ssh-keygen -lf "$possiblekey" | awk '{print $2}'` || ssh-add "$possiblekey" > /dev/null 2>&1 | |
fi | |
done | |
} | |
if [ -f "${SSH_ENV}" ]; then | |
. "${SSH_ENV}" > /dev/null | |
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { | |
rm "${SSH_ENV}"; | |
start_agent; | |
} | |
else | |
start_agent; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment