我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
当前回答
我认为缓存凭据比永久存储更安全:
git config --global credential.helper 'cache --timeout=10800'
现在,您可以输入用户名和密码(git pull或…),并在接下来的三个小时内继续使用git。
它很好,很安全。
超时的单位是秒(在本例中为三小时)。
其他回答
我认为缓存凭据比永久存储更安全:
git config --global credential.helper 'cache --timeout=10800'
现在,您可以输入用户名和密码(git pull或…),并在接下来的三个小时内继续使用git。
它很好,很安全。
超时的单位是秒(在本例中为三小时)。
对于Windows用户,请查看.gitconfig文件并检查为凭据助手配置了什么。如果您有以下内容。。。
[凭证“helperselector”]selected=绞车
您将在Windows凭据管理器中找到凭据。
您可以在那里编辑凭证。
注意:Wincred已被弃用,请参阅。。。
https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-该项目不再处于警告状态
因此,您可能需要重新配置Git以使用内置的Git凭据管理器。。。
git config --global credential.helper manager
打开凭据助手,以便Git将您的密码保存在内存中一段时间:
在终端中,输入以下内容:
# Set Git to use the credential memory cache
git config --global credential.helper cache
默认情况下,Git将缓存您的密码15分钟。
要更改默认密码缓存超时,请输入以下内容:
# Set the cache to timeout after 1 hour (setting is in seconds)
git config --global credential.helper 'cache --timeout=3600'
来自GitHub帮助。
推荐的安全方法:SSH
创建SSH GitHub密钥。转到github.com→ 设置→ SSH和GPG密钥→ 新SSH密钥。现在将您的私钥保存到计算机。
然后,如果私钥保存为~/.ssh/目录中的id_rsa,我们将其添加为身份验证:
ssh-add -K ~/.ssh/id_rsa
更安全的方法:缓存
我们可以使用git凭据缓存在一段时间内缓存用户名和密码。只需在CLI(终端或命令提示符)中输入以下内容:
git config --global credential.helper cache
您还可以按如下方式设置超时时间(以秒为单位):
git config --global credential.helper 'cache --timeout=3600'
您可以使用git凭据存储将未加密的密码存储在磁盘上,仅受文件系统权限的保护。
实例
git config credential.helper store
git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
[Several days later]
git push http://example.com/repo.git
[Your credentials are used automatically]
您可以检查存储在文件~/.git凭据中的凭据。
有关更多信息,请访问git credential store-Helper将凭据存储在磁盘上。