GitHub 不再支持密码验证,如何在 macOS 上实现 Token 登陆配置

这两天我发现用 GitHub 的时候,push 不了代码了,不停地出如下的问题:

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: 无法访问 'https://github.com/iphysresearch/GWToolkit.git/':The requested URL returned error: 403

其实官方早在去年年底的官方博文就给出了上面链接的说明,同时最近的官方博文中也有着详细的解释:

As previously announced, starting on August 13, 2021, at 09:00 PST, we will no longer accept account passwords when authenticating Git operations on GitHub.com. Instead, token-based authentication (for example, personal access, OAuth, SSH Key, or GitHub App installation token) will be required for all authenticated Git operations.

Please refer to this blog post for instructions on what you need to do to continue using git operations securely.

简单来说,就是从 2021 年 8 月 13 号开始,在 GitHub.com 上任何授权 Git 的行为都不再支持密码验证了,请用使用基于 token 的授权方式来替代,比如说:personal access, OAuth, SSH Key, or GitHub App installation token

(以下为正文)


下面就是基于我的 macOS 系统完成的配置并解决文体,仅供参考。

FYI:如果你想自己学着根据官方材料配置的话,可以参考如下两个链接就足够了。

总共两步:

第一步,先到 GitHub 个人设置里设置 token。

  • 打开自己的 GitHub主页,点击自己的头像找到 Settings 并进入,在左边目录栏找到 Developer settings - Personal access tokens,点击 Generate new token,按照步骤申请即可,过程简单。Scopes(范围)那里建议全选。

Token 申请成功后,一定记得要复制保存下来这个 token 字符串,因为这是你最后一次看到它的机会,忘记了的话 GitHub.com 是不会给你查找的,你只能重新申请新的。

第二步,在 macOS 的钥匙串访问里修改 GitHub 的密码为刚刚获得的 token。

用 Spotlight 或者 Alfred 等找到钥匙串访问 (Keychain Access),并打开。

右上方搜索 github.com,然后种类类别里找到 互联网密码(internet password),双击这个条目打开以后,在密码处填入第一步中复制保存下来的 token,最后存储更改即可。

Next
Previous

Related