Github新安全措施:停止Git客户端账号密码登录的解决方案

今年 8 月 13 日之后,如果你还用账户密码来操作 Github 上的仓库,就会收到如下警告:

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: unable to access 'https://github.com/<user>/<repo>/': The requested URL returned error: 403

解决方案就是使用访问令牌(AccessToken)。如果Git 客户端提示你需要登录 Github,账户输入oauth2,密码输入你的令牌。

如果你已经用账户密码登录过了。在推送的时候,不会提示你登录,而是直接报错。这种情况就需要打开~/.git-credentials文件,这个是Git客户端储存账号密码的地方。找到@github.com,把前面的用户名密码替换成oauth2:<token>,即大功告成。

注意,如果你的用户名密码在你仓库的远程 URL 里面,同样需要用git remote set-url来替换掉。

其实所有 Git 服务端都可以这样操作,这样支持权限隔离和细粒度控制,避免一码通密码,更加安全。

posted @ 2021-08-14 17:21  绝不原创的飞龙  阅读(311)  评论(0编辑  收藏  举报