Created
August 28, 2017 17:23
-
-
Save fstamour/4fdc594784cc257ea97c22356422d3b1 to your computer and use it in GitHub Desktop.
Start ssh agent if not running and save environment variable to share the agent across shell. Useful on Windows.
This file contains hidden or 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
start_ssh_agent_if_not_running () { | |
local SSH_ENVIRONMENT_FILE=~/.ssh/environment | |
if [ -f "$SSH_ENVIRONMENT_FILE" ]; then | |
source "$SSH_ENVIRONMENT_FILE" | |
fi | |
echo SSH_AGENT_PID='"'${SSH_AGENT_PID}'"' | |
if [ ! -z ${SSH_AGENT_PID} ] && ps -p ${SSH_AGENT_PID} > /dev/null | |
then | |
echo "ssh agent already running" | |
else | |
echo "starting ssh agent..." | |
ssh-agent -s > "${SSH_ENVIRONMENT_FILE}" | |
cat "${SSH_ENVIRONMENT_FILE}" | |
fi | |
if [ -f "$SSH_ENVIRONMENT_FILE" ]; then | |
source "${SSH_ENVIRONMENT_FILE}" | |
fi | |
} | |
start_ssh_agent_if_not_running |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment