Skip to content

Instantly share code, notes, and snippets.

@teerapap
Created March 11, 2014 07:07
Show Gist options
  • Save teerapap/9480910 to your computer and use it in GitHub Desktop.
Save teerapap/9480910 to your computer and use it in GitHub Desktop.
bashrc to initialize ssh-agent daemon(if not running) on ssh-login
####SSH-agent setting####
AGENT_INFO="$HOME/.ssh/agent.info"
function start_agent {
echo "Initializing new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${AGENT_INFO}"
chmod 600 "${AGENT_INFO}"
. "${AGENT_INFO}" > /dev/null
}
# Source SSH settings, if applicable
if [ -f "${AGENT_INFO}" ]; then
. "${AGENT_INFO}" > /dev/null
ps -p ${SSH_AGENT_PID} > /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