在这篇博文中,我们有很多方法可以为git推送命令保存用户凭证。
大家都知道,每次向GitHub推送修改时,都需要用用户名和密码来认证GitHub。
有些时候,你想在不认证的情况下多次提交,有一个过程可以做到这一点。
git-credential-store和git-credential-cache是将用户证书存储到硬盘的命令。
这些命令只具有文件系统的权限。
git-credential-store示例
这些命令用于将凭证存储到本地存储。这些证书可以无限期地保存。
$ git config credential.helper cache
$ git push http://github.com/repository.git
Username:
Password:
[next time ownards, entering user details are not required]
$ git push http://github.com/repository.git
[credentials are not required to enter again, ]
禁用该存储
git config --unset credential.helper
git-credential-cache 例子
这些将被存储在本地缓存中。这些证书在特定的时间段内保存。
$ git config credential.helper cache
$ git push http://github.com/repository.git
Username:
Password:
[next time ownards, entering user details are not required]
$ git push http://github.com/repository.git
[credentials are not required to enter again, ]
这将使凭证存储在文件系统缓存中,默认为15分钟 启用存储时间 如果你想在某个时间段内存储凭证。下面的超时时间是50分钟
git config --global credential.helper 'store --timeout=3000'
这种方法的缺点是用户凭证以纯文本形式存储,不安全。另一种方法是使用SSH,将公钥和私钥添加到github上。