个人访问令牌在Linux上不工作



我在Linux上使用Git。我按照这个步骤创建了一个个人访问令牌,但忘记保存它。因此,当我被要求输入"密码"时;同样,我删除了旧的PAT并创建了一个新的PAT。由于某种原因,新的令牌被拒绝了,我得到

fatal: Authentication failed for 'https://github.com/username/***.git/'

当我查看github上的令牌页面时,这个令牌说它从未使用过。这里的问题是什么呢?

问题可能与您当前的凭据帮助器有关。

输入git config credential.helper查看使用的是哪一个。

类型:

printf "protocol=httpsnhost=github.com"|git-credential-xxx erase

(将xxx替换为第一个命令输出中的凭据助手名称)

这将清除https://github.com的缓存凭据。

然后再试一次git push,看看它是否要求您输入凭据:输入您的新PAT作为密码。

如果你没有一个凭证助手,我建议安装microsoft/Git-Credential-Manager-Core(有一个Linux包)。
添加凭据存储,然后设置。

讨论:后

  • 没有凭据辅助器
  • 这是个人帐户(不是技术服务帐户,由多个用户使用)
  • 问题是粘贴令牌

因此,我将使用存储凭据缓存:

git config --global credential.helper 'store --file /home/<user>/.my-credentials

:

git ls-remote https://github.com/<user>/<repo>

将触发提示输入您的用户名和令牌。

编辑/home/<user>/.my-credentials,并确保其中有正确的令牌。


或者

git config --global credential.helper 'store --file /home/<user>/.my-credentials'

然后:

git ls-remote https://<user>:<token>@github.com/<user>/<repo>

工作。

我不得不删除我的令牌并创建一个新的,它为我工作

最新更新