问题
This is becoming even more important now with the new 2-factor authentication, as one has to create a new token each time a password is required on the terminal. Basically, I'm looking for an equvalent to the osxkeychain available in OS X that I could use on Linux desktops and servers:
git config --global credential.helper osxkeychain
I searched through the possible solutions, but so far I don't like any of them:
- ssh instead of https - not recommended and links not easily accessible on GitHub
cache --timeout=3600
- it will expire eventually and reentering the password is a drag with the new 2FA- gnome-keyring - doesn't work on a headless server (at least not too elegantly - the ssh passphrase keyring is much nicer)
- the encrypted .netrc file on my hard-drive method - poor man's manual keyring implementation?
Come on, there's got to be some proper terminal-based keychain for Linux that can be hooked to git's credential.helper!
回答1:
I would still recommend the method I describe in "Is there a way to skip password typing when using https://github.com"
Encrypting your .netrc
allows you to store multiple credentials (to GitHub, and BitBicket, and ...) in one file, and have it used through the git credential helper netrc
(git1.8.3+).
And it is compatible with the Github two-factor authentication, as I detail in "Configure Git clients, like GitHub for Windows, to not ask for authentication".
It works on Windows (and Linux or Mac).
And you can limit the number of minutes/hours during which gpg won't ask you again for the private key passphrase.
回答2:
This method is not recommend, but still if you are in rush and nothing else is working for you, Simply add a new remote as
git remote -rm origin
git remote add origin https://username:mypassword@github.com/path/to/repo.git
that's it now you don't need to enter password again and again
Note: This method doesn't work with two step authorization accounts
来源:https://stackoverflow.com/questions/18838579/how-to-store-your-github-https-password-on-linux-in-a-terminal-keychain