Configuring credential.helper
On OS X (now macOS), run this in Terminal:
git config
It enables Git to use file 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
For Linux use:
git config --global credential.helper cache
OR
git config --global credential.helper store
Note: The first method will cache the credentials in memory, whereas the second will store them in ~/.git-credentials
in plain text format.
Check here for more info about Linux method.
Check here for more info about all three.
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 v10.12 (Sierra) changes to ssh
For macOS v10.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.
netrc
'. See a full example here. – VonC