Skip to content

Instantly share code, notes, and snippets.

@sharumpe
Created August 11, 2017 19:34
Show Gist options
  • Save sharumpe/132b45f62afb0ed3df29d442ec3deb7c to your computer and use it in GitHub Desktop.
Save sharumpe/132b45f62afb0ed3df29d442ec3deb7c to your computer and use it in GitHub Desktop.
Set up Linux to use an ssh-agent at login
## References
# http://www.cygwin.com/ml/cygwin/2001-06/msg00537.html
# https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
# I've modified the script in the first to work with the MacOS-specific info in
# the second. The procedure below should get you what you need, though.
# Postreq: Add the below (or a reference to it) to .profile or similar.
# ssh-agent: Where we're tracking the ssh-agent settings
SSH_ENV="$HOME/.ssh/environment"
# ssh-agent: Start the agent and track the settings
function start_ssh_agent {
echo -n "Initialising new SSH agent: "
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo "Done"
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
# ssh-agent: Check that the agent is running; If not, start it.
function ensure_ssh_agent {
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_ssh_agent;
}
else
start_ssh_agent;
fi
}
# ssh-agent: kickoff
ensure_ssh_agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment