Skip to content

Instantly share code, notes, and snippets.

@jdevera
Created October 13, 2016 10:03
Show Gist options
  • Save jdevera/854b8fcba903919261e95312660da6bb to your computer and use it in GitHub Desktop.
Save jdevera/854b8fcba903919261e95312660da6bb to your computer and use it in GitHub Desktop.
Function to start an ssh agent or load a running one into the current environment
function ssh-agent-start()
{
local agentfile=~/.ssh/agent
if [[ -f $agentfile ]]
then
source $agentfile > /dev/null
if ps -p "$SSH_AGENT_PID" > /dev/null
then
echo "Agent running with PID $SSH_AGENT_PID"
return
fi
fi
echo "Could not find running agent. Starting new..."
ssh-agent > $agentfile
source $agentfile > /dev/null
echo "Agent running with PID $SSH_AGENT_PID"
ssh-add
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment