I created keys as instructed in the github tutorial, registered them with github, and tried using ssh-agent explicitly — yet git continues to ask me for my passphrase every
What worked for me on Windows was (I had cloned code from a repo 1st):
eval $(ssh-agent)
ssh-add
git pull
at which time it asked me one last time for my passphrase
Credits: the solution was taken from https://unix.stackexchange.com/questions/12195/how-to-avoid-being-asked-passphrase-each-time-i-push-to-bitbucket
It sounds like you may be having trouble with SSH-Agent itself. I would try troubleshooting that.
1) Did you do ssh-add to add your key to SSH?
2) Are you closing the terminal window between uses, because if you close the window you will have to enter the password again when you reopen it.
I would try the following:
~/.bashrc
file
SSH_ENV=$HOME/.ssh/environment
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
echo succeeded
chmod 600 ${SSH_ENV}
. ${SSH_ENV} > /dev/null
/usr/bin/ssh-add
}
if [ -f "${SSH_ENV}" ]; then
. ${SSH_ENV} > /dev/null
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
Once you have started the SSH agent with:
eval $(ssh-agent)
You have to add your private key to it:
ssh-add
This will ask you your passphrase just once, and then you should be allowed to push, provided that you uploaded the public key to Github.
To save key permanently on macOS:
ssh-add -K
This will persist it after you close and re-open it by storing it in user's keychain.
If you've tried ssh-add
and you're still prompted to enter your passphrase then try using ssh-add -K
. This adds your passphrase to your keychain.
Update: if you're using macOS Sierra then you likely need to do another step as the above might no longer work. Add the following to your ~/.ssh/config
:
Host *
UseKeychain yes
Try adding this to your ~/.ssh/config:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
... assuming your private key is named id_rsa