Github即日起不再支持基于密码的授权方式:Support for password authentication was removed on August 13, 2021

去年年底,Github官方层发公告推荐用户更新授权方式,从密码改为令牌,并将于2021年的8月13日完全停止密码的使用

image.png
https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/


Github 用户操作个人代码仓库时一般有两种方式,基于https和基于ssh。其中前者需要用户通过密码验证身份并进行后续操作。但是由于密码容易泄露等和易被盗取,安全性不足。虽然Github增加了双因素身份验功能,但是由于历史原因,很多用户仍然使用仅使用其用户名和密码进行验证,漏洞颇多。

鉴于此原因,从今年8月13日起,Github 对 Git 操作进行身份验证时不再接受帐户密码,并将要求使用基于令牌(token)的身份验证。 使用 SSH 方式的用户不受影响。

如果你还没有更换授权方式,当你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: unable to access 'https://github.com/your_name/repo.git/': The requested URL returned error: 403

token的优势

  • 唯一性: token只服务于Github,按需生成,不会因为用户其它网站的密码泄露而产生风险
  • 可撤销:token可随时撤销,更加安全。
  • 范围可控:生成token时可以选择授权范围,甚至可以针对不同权限生成不同token
  • 随机性,token没有固定的密码形式,难以被记忆,自然也不会遗忘

创建token

image.png

Settings > Developer settings > Generate new token

然后输入授权有效期,并勾选token的操作范围

image.png

点击 Generate token

注意:要将token复制到剪贴板。 因为出于安全原因,离开此页面后,您将无法再次看到token。

使用token

后续进行 HTTPS 操作就可以使用此token了,以 push 代码为例

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

将 token 填入 密码即可

如果你在 github 创建了 token, 但是 push 的时候没有提示输入,此时可以先输入以下命令

git config --system --unset credential.helper

此外也可以在https地址中加入token

$ git push https://$your_token@github.com/username/repo.git

如果嫌每次敲命令都需要输入token太麻烦,也可以把令牌直接添加远程仓库链接中,这样就可以避免同一个仓库每次提交代码都要输入token

$ git remote set-url origin https://$your_token@github.com/username/repo.git
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fundroid

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值