Created
July 5, 2017 18:54
-
-
Save sharumpe/aac2f5ba8a2a54c005124d1eb9e93757 to your computer and use it in GitHub Desktop.
Set up Mac OS X Sierra to use an ssh-agent at 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
## 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. | |
# Prereq: $HOME/.ssh/config must contain: | |
# Host * | |
# AddKeysToAgent yes | |
# UseKeychain yes | |
# IdentityFile ~/.ssh/id_rsa | |
# IdentityFile ~/.ssh/... #other private keys | |
# 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 -K; | |
} | |
# 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