I'm using Linux and 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 time I try to do a pull or a push.
What could be the cause?
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:
ssh-add -K
This will persist it after you close and re-open it by storing it in user's keychain.
git pull
, prompt me for password again - kyo 2016-10-03 22:31
ssh-add
command, e.g. ssh-add /Users/rubyx/.ssh/git/id_rsa
Rubix 2017-01-04 17:08
ssh-add -K
will persist it after you close and re-open it by storing it in user's keychain - Kirk 2017-01-07 01:05
ssh-add -K
gives the following:
unknown option -- K
usage: ssh-add [options] [file ...]
Options:
-l List fingerprints of all identities.
-L List public key parameters of all identities.
-k Load only keys and not certificates.
-c Require confirmation to sign using identities
-t life Set lifetime (in seconds) when adding identities.
-d Delete identity.
-D Delete all identities.
-x Lock agent.
-X Unlock agent.
-s pkcs11 Add keys from PKCS#11 provider.
Sandeep C 2017-02-12 10:35
git config credential.helper store
After that I was asked one more time for my credentials, but after that no more - eztam 2018-05-14 14:51
-K
is apple specific. See https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#adding-your-ssh-key-to-the-ssh-agen - bkdir 2018-07-17 15:32
This has been happening to me after restarts since upgrading from OS X El Capitan (10.11) to macOS Sierra (10.12). The ssh-add
solution worked temporarily but would not persist across another restart.
The permanent solution was to edit (or create) ~/.ssh/config
and enable the UseKeychain
option.
Host *
UseKeychain yes
Related: macOS keeps asking my ssh passphrase since I updated to Sierra
ssh-add -K /Users/***/.ssh/git/id_rsa
but it was still not working after terminal restart... thank you - nawlbergs 2017-01-19 15:12
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
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
zsh
. Just add this to .zshrc
Arda 2015-07-21 11:11
id_rsa
. If you have a custom name, you should use eg. /usr/bin/ssh-add ~/.ssh/custom_filename
Juha Untinen 2016-08-04 09:37
Try adding this to your ~/.ssh/config:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
... assuming your private key is named id_rsa
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
I had a similar issue, but the other answers didn't fix my problem. I thought I'd go ahead and post this just in case someone else has a screwy setup like me.
It turns out I had multiple keys and Git was using the wrong one first. It would prompt me for my passphrase, and I would enter it, then Git would use a different key that would work (that I didn't need to enter the passphrase on).
I just deleted the key that it was using to prompt me for a passphrase and now it works!
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.
If the above solutions are not working for me, one thing to check is that you actually have the public key too (typically id_rsa.pub
). It is unusual not to, but that was the cause for me.
To create your public key from your private key:
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
I try different solutions but nothing help. But this steps (My GitBash SSH environment always asks for my passphrase, what can I do?) from Bitbucket.com seams works well :
The idea is:
you create ~/.bashrc
file
add follow script:
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
re-run Bash
To avoid git being asking for password once you have generated and configured ssh keys, don't use https, instead use:
git@bitbucket.org:<repo_owner>/<reponame>.git
or
ssh://git@bitbucket.org/<repo_owner>/<reponame>.git