Created
May 2, 2012 17:48
-
-
Save rbriank/2578640 to your computer and use it in GitHub Desktop.
Script to run ssh-agent, and ssh-add on login
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
# Add to ~/.bash_profile | |
# Start/Reuse SSH Agent - restart or re-use an existing agent | |
SSH_AGENT_CACHE=/tmp/ssh_agent_eval_`whoami` | |
if [ -s "${SSH_AGENT_CACHE}" ] | |
then | |
echo "Reusing existing ssh-agent" | |
eval `cat "${SSH_AGENT_CACHE}"` | |
# Check that agent still exists | |
kill -0 "${SSH_AGENT_PID}" 2>- | |
if [ $? -eq 1 ] | |
then | |
echo "ssh-agent pid ${SSH_AGENT_PID} no longer running" | |
# Looks like the SSH-Agent has died, it'll be restarted below | |
rm -f "${SSH_AGENT_CACHE}" | |
fi | |
fi | |
if [ ! -f "${SSH_AGENT_CACHE}" ] | |
then | |
echo "Starting new ssh-agent" | |
touch "${SSH_AGENT_CACHE}" | |
chmod 600 "${SSH_AGENT_CACHE}" | |
ssh-agent >> "${SSH_AGENT_CACHE}" | |
chmod 400 "${SSH_AGENT_CACHE}" | |
eval `cat "${SSH_AGENT_CACHE}"` | |
# add your own key | |
ssh-add ~/.ssh/some_key_file | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone stumbling upon this now, it's no longer necessary. See http://superuser.com/a/269570/393696