密码认证因停电而暂时禁用,请使用个人访问令牌代替。

243

我之前一直使用用户名密码推送我的代码,几个月来都能正常工作。但是突然间无法推送并出现了以下错误:

Username for 'https://github.com': shreyas-jadhav
Password for 'https://shreyas-jadhav@github.com':
remote: Password authentication is temporarily disabled as part of a brownout. Please use a personal access token instead.
remote: Please see https://github.blog/2020-07-30-token-authentication-requirements-for-api-and-git-operations/ for more information.

请注意,链接没有帮助。即使使用生成的令牌也无济于事。

版主提示:这是GitHub计划中即将永久性服务变更的一部分


4
GitHub将移除用户名密码身份验证,从现在开始您需要使用令牌(Token)。 - Liam
21
阅读该网页基本上告诉您所有这些内容。 - Liam
20
我有同样的问题,但那个页面并没有帮助。问题在于,即使使用生成的令牌作为密码,仍会出现相同的错误消息。 - Narann
15
为什么会用到“brownout”这个词? - Ross Presser
7
“Brownout”是指电力损失部分而非全部的情况。这个词源于白炽灯泡时代,当电力损失少许时,灯泡会明显变暗。在此语境下,GitHub正在“降低亮度”,以告知用户服务即将有所改变(即密码很快将完全停止使用)。 - Machavity
显示剩余17条评论
25个回答

5

Ubuntu服务器和现有Git仓库的解决方案

移除密码:

git config --global --unset user.password;
git config --local --unset user.password;

更改 remote.origin.url, 将 <username> 替换为您的 GitHub 用户名:

git config --global --replace-all remote.origin.url "https://<username>@github.com/PPEProjects/smile-eyes-be.git";
git config --local --replace-all remote.origin.url "https://<username>@github.com/PPEProjects/smile-eyes-be.git"

拉取/推送

git pull
git push origin HEAD:develop

输入从个人访问令牌生成的个人访问令牌。


4

首先来自这篇文章:API和Git操作的令牌身份验证要求,其中提到:

在2021年中期之前,所有经过身份验证的Git操作都需要使用个人访问或OAuth令牌。

因此,您需要使用个人访问令牌(PAT)来进行推送:

1 获取个人访问令牌

在此处登录以访问存储库并添加新的个人访问令牌:个人访问令牌。生成一个并将令牌保管好(一旦离开页面就无法再次查看)。

(在Android Studio中,您需要获取“repo”、“gist”和“read:org”的权限)

2 使用个人访问令牌进行推送

在获得令牌后,您可以使用类似以下命令的push进行推送:

git push https://[personal access token]@github.com/[user name]/[repository Name].git

感谢您发布这篇文章,因为它也适用于Gist,例如 git push https://[Personal Access Token]@gist.github.com/[Gist ID].git。我需要这个功能,因为尽管在创建我的令牌时检查了“create” Gist选项,并且使用git进行存储库交互,但在2021年8月13日之后,将内容推送到Gist时出现了问题。 - Wayne

4
尝试以下步骤(我已成功实践):
  1. 按照这个指南生成SSH密钥:生成新的SSH密钥
  2. 使用 git remote remove origin 命令删除所有使用HTTPS的旧远程地址;
  3. 使用一个SSH引用添加新的远程地址(您可以在代码库中点击“代码”按钮,然后选择“ssh”来获取它)。

enter image description here


3

您只需要使用生成的令牌代替传统密码:

旧方法使用密码

git clone https://github.com/username/repo.git

Username: your_username
Password: your_password

使用令牌的新方法:

git clone https://github.com/username/repo.git

Username: your_username
Password: your_token

步骤1: 从GitHub生成API令牌

步骤2: 将先前缓存的密码替换为新生成的令牌


3
当我尝试在Visual Studio Code中提交(push)时,我收到了这个错误... 但是当我打开终端并使用用户名和密码提交(push),没有任何问题。也许你可以尝试一下这种方法。

3

这个方法适用于我:

  1. Generate the personal access token (don't forget to copy the token)

  2. Open your Keychain Access (Mac) or Credential Manager (Windows).

  3. Update the GitHub password with the new personal access token in KeyChain Access/Credential Manager

  4. Last step: Do a Git clone (make sure you clone the repository in the proper directory location)

    git clone https://github.com/username/repo.git
    
    Username: your_username
    Password: your_token
    

在我的情况下,它没有提示我输入用户名和密码,因为它已经在 Keychain Access 中更新了。


2

GitHub正在移除用户名密码身份验证

与其他人提到的替代方法不同:

您可以安装和配置GitHub CLI。使用OAuth设置更好。没有必要手动从钥匙串中删除凭据。

在macOS上,使用Homebrewbrew)进行安装甚至更简单:

运行brew install gh并按照以下步骤操作:

  1. 您想登录哪个帐户?选择GitHub
  2. 您偏好的Git操作协议是什么?选择HTTPS
  3. 使用您的GitHub凭据对Git进行身份验证?选择YES
  4. 您想如何验证GitHub CLI?选择使用Web浏览器登录
  5. 复制终端中显示的代码-> B7C1-8E67
  6. Enter在浏览器中打开github.com
  7. 使用浏览器进行身份验证

完成。

像往常一样开始使用Git命令。


2
以下步骤完美适用于我:

按照以下步骤操作:

  • 从GitHub生成访问令牌,设置开发人员设置个人访问令牌生成新令牌

  • 保存令牌 - 仅可使用一次

  • 在系统中搜索.git-credential文件

  • 在用户名后面的文件中使用访问令牌代替密码。


2

1
我在第一个脚本上运气不佳,但是评论中的这个脚本完美地运行了:https://gist.github.com/m14t/3056747#gistcomment-3468753 - JP.

1

如果你使用HTTPS而不是SSH,那么会出现这个错误,因为GitHub正在删除HTTPS方法来维护仓库。

  1. 如果你没有生成SSH密钥,则可以通过ssh-keygen命令生成。在执行命令时,一路按回车键即可。
  2. cat ~/.ssh/id_rsa.pub - 复制结果。
  3. 访问https://github.com/settings/keys
  4. 点击New SSH Key按钮,并将密钥粘贴到文本框中。标题可以随意设置。
  5. cd <进入你的项目目录>
  6. git remote set-url origin git@github.com:<用户名>/<仓库名称>.git

然后就可以开始了!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接