我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。

有没有办法缓存凭据,而不是每次git推送时都进行身份验证?


当前回答

composer文档提到,您可以阻止它使用GitHub API,这样它的行为就像gitclone:

如果在GitHub存储库中将no-api键设置为true,它将像克隆任何其他Git存储库一样克隆存储库,而不是使用GitHub api。但与直接使用git驱动程序不同,composer仍然会尝试使用GitHub的zip文件。

因此,该部分将如下所示:

"repositories": [
    {
        "type": "vcs",
        "no-api": true,
        "url": "https://github.com/your/repo"
    }
],

请记住,API存在是有原因的。因此,这应该是github.com上增加负载的最后手段。

其他回答

为了安全起见,最好使用凭据,但您可以使用缓存将其保存一段时间:

git config --global credential.helper cache
git config credential.helper 'cache --timeout=3600'

您的凭据将保存3600秒。

我从gitcredentials(7)手册页面得到了答案。就我而言,我的Windows安装中没有凭据缓存;我使用凭据存储。

使用凭据存储后,用户名/密码存储在[用户文件夹]/.git凭据文件中。要删除用户名/密码,只需删除文件的内容。

在Ubuntu上使用GitCredentialManager(GCM)在本地缓存凭据,在Ubuntu 20.04和18.04上进行了测试,但应该可以在其他Linux发行版上运行。

设置git凭据管理器:

curl -LO https://raw.githubusercontent.com/GitCredentialManager/git-credential-manager/main/src/linux/Packaging.Linux/install-from-source.sh
sh ./install-from-source.sh
git-credential-manager-core configure
git config --global credential.credentialStore cache
git config --global credential.cacheoptions "--timeout 72000"
sudo rm -rf git-credential-manager/
sudo rm install-from-source.sh

转到回购并运行git fetch选择设备代码访问链接并输入输出中提供的代码

截至2021,HTTPS远程有一个安全、用户友好的跨平台解决方案。不再输入密码!不再有SSH密钥!不再有个人访问令牌!

安装GitHub开发的Git凭据管理器(下载)。它支持对GitHub、BitBucket、Azure和GitLab的无密码OAuth认证。这意味着您可以在GitHub和其他平台上启用双因素身份验证,大大提高了帐户的安全性。

推送时,您可以选择身份验证方法:

> git push
Select an authentication method for 'https://github.com/':
  1. Web browser (default)
  2. Device code
  3. Personal access token
option (enter for default): 1
info: please complete authentication in your browser...

在Linux上,需要一点点设置。以下内容将凭据缓存在内存中20小时,因此您每天最多只能进行一次身份验证。

git-credential-manager-core configure
git config --global credential.credentialStore cache
git config --global credential.cacheoptions=--timeout 72000

熟悉gnomekeyring或KWallet的高级用户可能更喜欢将凭证存储更改为libsecret。

外观配置:由于我总是在上面的提示下选择“web浏览器”,所以我设置了gitHubAuthModes首选项来跳过选择。GCM的最新版本包括一个GUI,它为授权流添加了额外的点击,我禁用了它。

git config --global credential.gitHubAuthModes browser
git config --global credential.guiPrompt false

你可以使用

git config credential.helper store

当您下次使用pull或push输入密码时,它将以明文形式存储在文件.git凭据中(有点不安全,但只需将其放入受保护的文件夹中)。

如本页所述:

git凭证存储