Git keeps prompting me for password

I've been using Git for a while now, but the constant requests for a password are starting to drive me up the wall.

I'm using OSX and Github, and I set up Git and my SSH keys as instructed by GitHub's Set Up Git page . I've also added the github SSH key to my Mac OSX keychain, as mentioned on GitHub's SSH key passphrases page . My public key is registered with Git.

Nevertheless, every time I try to git pull, I have to enter my username and password. Is there something other than an SSH key that I need to set up for this?


I think you may have the wrong git repo url.

Open .git/config and find the [remote "origin"] section. Make sure you're using the SSH one:

ssh://git@github.com/username/repo.git

And NOT the https or git one:

https://github.com/username/repo.git
git://github.com/username/repo.git

You can now validate with just the SSH Key instead of the username and password .

[Edit:] If Git complains that 'origin' has already been added , open the .config file and edit the url = "..." part after [remote origin] as url = ssh://github/username/repo.git


Configuring credential.helper

On OS X (now macOS) run this in the Terminal

git config --global credential.helper osxkeychain

It enables git to use Keychain.app to store username and password and to retrieve the passphrase to your private ssh key from the keychain.

For windows use:

git config --global credential.helper wincred

Troubleshooting

If the git credential helper is configured correctly macOS saves the passphrase in the keychain. Sometimes the connection between ssh and the passphrases stored in the keychain can break. Run ssh-add -K or ssh-add ~/.ssh/id_rsa to add the key to keychain again.

macOS 10.12 Sierra changes to ssh

For macOS 10.12 Sierra ssh-add -K needs to be run after every reboot. To avoid this create ~/.ssh/config with this content.

Host *
   AddKeysToAgent yes
   UseKeychain yes
   IdentityFile ~/.ssh/id_rsa

From the ssh_config man page on 10.12.2:

UseKeychain

On macOS, specifies whether the system should search for passphrases in the user's keychain when attempting to use a particular key. When the passphrase is provided by the user, this option also specifies whether the passphrase should be stored into the keychain once it has been verified to be correct. The argument must be 'yes' or 'no'. The default is 'no'.

Apple has added Technote 2449 which explains what happened.

Prior to macOS Sierra, ssh would present a dialog asking for your passphrase and would offer the option to store it into the keychain. This UI was deprecated some time ago and has been removed.


This happened to me when I upgraded to macOS Sierra. Looks like the ssh agent got cleared upon upgrade.

$ ssh-add -L
The agent has no identities.

Simply running ssh-add located my existing identity, entered the password and good to go again.

链接地址: http://www.djcxy.com/p/22056.html

上一篇: 缓存'不是一个git命令

下一篇: Git不断提示我输入密码