我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。
有没有办法缓存凭据,而不是每次git推送时都进行身份验证?
我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。
有没有办法缓存凭据,而不是每次git推送时都进行身份验证?
当前回答
在GNU/Linux设置中,~/.netrc也非常有效:
$ cat ~/.netrc
machine github.com login lot105 password howsyafather
这可能取决于Git用于HTTPS传输的网络库。
其他回答
使用凭据存储。
对于OS X和Linux上的Git 2.11+,请使用Git内置的凭据存储:
git config --global credential.helper libsecret
对于Windows上的msysgit 1.7.9+:
git config --global credential.helper wincred
对于OS X上的Git 1.7.9+,请使用:
git config --global credential.helper osxkeychain
双因素身份验证改变了用户对网站的身份验证方式,但Git仍然假设用户可以从内存中键入密码。
介绍git credential oauth:一个git凭据助手,可以使用oauth安全认证GitHub、GitLab、BitBucket和其他伪造文件。
没有更多密码!不再有个人访问令牌!不再有SSH密钥!第一次推送时,助手将打开浏览器窗口进行身份验证。缓存超时内的后续推送不需要交互。
从安装https://github.com/hickford/git-credential-oauth/releases/
配置方式:
git config --global --unset-all credential.helper
git config --global --add credential.helper "cache --timeout 7200" # two hours
git config --global --add credential.helper oauth
如果你不想像Mark所说的那样以明文形式存储密码,你可以使用不同的GitHub URL进行抓取,而不是推送。在配置文件中的[远程“原点”]下:
url = git://github.com/you/projectName.git
pushurl = git@github.com:you/projectName.git
当您推送时,它仍然会要求输入密码,但当您获取时,它不会要求输入密码。
为了安全起见,最好使用凭据,但您可以使用缓存将其保存一段时间:
git config --global credential.helper cache
git config credential.helper 'cache --timeout=3600'
您的凭据将保存3600秒。
有一种简单、老式的方法可以将用户凭据存储在HTTPS URL中:
https://user:password@github.com/...
您可以使用git remote set URL<remote repo><URL>更改URL
这种方法的明显缺点是必须以纯文本存储密码。您仍然可以只输入用户名(https://user@github.com/…),这至少可以为您省去一半的麻烦。
您可能更喜欢切换到SSH或使用GitHub客户端软件。