git 如何在终端钥匙串中存储 Linux 上的 github https 密码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18838579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to store your github https password on Linux in a terminal keychain?
提问by metakermit
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:
现在使用新的 2 因素身份验证变得更加重要,因为每次在终端上需要密码时都必须创建一个新令牌。基本上,我正在寻找一个等效于 OS X 中可用的 osxkeychain,我可以在 Linux 桌面和服务器上使用它:
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 recommendedand 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?
- ssh 而不是 https -不推荐并且链接在 GitHub 上不容易访问
cache --timeout=3600
- 它最终会过期,重新输入密码是新的 2FA的拖累- gnome-keyring - 在无头服务器上不起作用(至少不是太优雅- ssh 密码密钥环要好得多)
- 我的硬盘驱动器方法上的加密 .netrc 文件 - 穷人的手动密钥环实现?
Come on, there's got to be some proper terminal-based keychain for Linux that can be hooked to git's credential.helper!
来吧,必须有一些适合 Linux 的基于终端的钥匙串,可以连接到 git 的 credential.helper!
回答by VonC
I would still recommend the method I describe in "Is there a way to skip password typing when using https://github.com
"
我仍然会建议我在描述方法“有没有办法跳过输入密码时,使用https://github.com
”
Encrypting your .netrc
allows you to store multiplecredentials (to GitHub, and BitBicket, and ...) in one file, and have it used through the git credential helper netrc
(git1.8.3+).
加密您.netrc
可以将多个凭据(到 GitHub、BitBicket 和...)存储在一个文件中,并通过 git 凭据助手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".
并且它与 Github 两因素身份验证兼容,正如我在“配置 Git 客户端,如 Windows 的 GitHub,不要求身份验证”中详细说明的那样。
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.
它适用于 Windows(以及 Linux 或 Mac)。
并且您可以限制 gpg 不会再次要求您提供私钥密码的分钟/小时数。
回答by Tarun Gupta
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:[email protected]/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
注意:此方法不适用于两步授权帐户