So, I use git and github with MFA, so, to avoid annoying password asking, for more than a year I am using the [email protected]:user/repo.git
URL style.
A couple of days ago, I ran a brew update
, and now, every time try to sync with github servers, git asks me the key password.
What I did so far:
Checked my configs, seems ok to me, but here it is (the relevant part):
[user]
name = Carlos Alexandro Becker
email = [email protected]
helper = osxkeychain
Tried to update git and osxkeychain, current versions are:
git 2.4.1
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
Cleaned osxkeychain for github.com
The one weird thing that I saw is this:
$ ssh-add ~/.ssh/id_rsa.pub
Could not open a connection to your authentication agent.
$ ssh-agent sh -c 'ssh-add ~/.ssh/id_rsa.pub'
Enter passphrase for /Users/carlos/.ssh/id_rsa.pub:
So, my guess is that somehow ssh-agent is not working properly, but I don't have any idea why nor how to fix it.
If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository.
Entering Git Username and Password in Remote URL To prevent Git from asking for your username and password, you can enter the login credentials in the URL as shown. The main drawback of this method that your username and password will be saved in the command in the Shell history file.
Since you mentioned, brew
, I assume you're running on a Mac. This has also happened to me and the solution was to ensure that I added the passphrase to the keychain (the Mac version of ssh-agent
, automatically launched on a Mac, includes keychain support):
$ ssh-add -K
And to store the passphrase for a different key:
$ ssh-add -K /path/to/private/key/file
Specifically in my case (since I use a separate key for GitHub):
$ ssh-add -K ~/.ssh/github_rsa
To automatically load keys into the ssh-agent and store passphrases in your keychain, you need to modify your ~/.ssh/config:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
I obtained this information from here:
The above addresses the OP issue for ssh keys. The following is also useful for Mac users if you want to cache your HTTPS credentials as well. You can do this by using a credential helper. To tell git to use the osxkeychain
helper, ensure this is added to your ~/.gitconfig
(or ~/.config/git/config
).
[credential]
helper = osxkeychain
Instead of editing the file directly, you can set this entry from the command line:
$ git config --global credential.helper osxkeychain
See these links for more detail (including how to verify that your system has the osxkeychain
helper installed):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With