今天在向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.
复制代码
经过仔细研究了一番报错,发现是从2021年8月14日之后,使用git对github进行身份验证操作的时候不再接受使用账号密码形式clone和push代码,之前使用账号密码形式的可以改为使用acces_token形式上传(具体博客:github.blog/2020-12-15-…)。
以下使用者不受此更改的影响:
- 如果您为您的帐户启用了双因素身份验证,则您已经需要使用基于令牌或基于 SSH 的身份验证。
- 如果您使用 GitHub Enterprise Server,我们尚未宣布对我们的本地产品进行任何更改。
为什么github要放弃账号密码形式,使用acces_token验证呢?
与基于密码的身份验证相比,Tokens提供了许多安全优势:
-
唯一– 令牌特定于 GitHub,可以按使用或按设备生成
-
可撤销– 可以随时单独撤销令牌,而无需更新未受影响的凭据
-
有限– 令牌可以缩小范围以仅允许用例所需的访问
-
随机– 令牌不受您需要记住或定期输入的更简单密码可能会受到的字典类型或蛮力尝试的影响
那具体怎么操作呢,去github的文档研究了一波。 github文档链接:docs.github.com/cn
查找access_token的步骤如下:
1、在github页面的右上角,单击您的个人资料照片,然后单击 Settings(设置) 。
![image.png](https://img-blog.csdnimg.cn/img_convert/43a1908d22d1d554d8c256e297de7348.webp?x-oss-process=image/format,png)
2、在左侧边栏中,单击 Developer settings。
![image.png](https://img-blog.csdnimg.cn/img_convert/5f7a2ca15868350cfc6649913b7b0b85.webp?x-oss-process=image/format,png)
3、在左侧边栏中,单击 Personal access tokens(个人访问Tokens) 。
![image.png](https://img-blog.csdnimg.cn/img_convert/36c26f79f305d5381231a3bcecdd1fe5.webp?x-oss-process=image/format,png)
4、点击 Generate new token(生成新Tokens) 。
![image.png](https://img-blog.csdnimg.cn/img_convert/2c63d905088f22014ce23aab284d6f7b.webp?x-oss-process=image/format,png)
5、设置名称,token过期日期,以及权限。
![image.png](https://img-blog.csdnimg.cn/img_convert/95e677407c7af2fb99136ea3c2324a47.webp?x-oss-process=image/format,png)
6、点击生成即可。
![image.png](https://img-blog.csdnimg.cn/img_convert/fba46a5da8f83869a01eb5839cff12de.webp?x-oss-process=image/format,png)
7、记得将生成的token复制并且存储下来,因为处于安全原因当您离开该页面之后,token将不再显示。
只需以下两步即可完成:
git remote remove origin // Remove old origin remote link
//You can run 'git remote -v' to have a look at the remote branch
git remote add origin https://<token>@github.com/<github-name>/<repo-name>.git
git push --set-upstream origin master // First push to the remote branch.
当然您也可以使用双重认证的方式。
由此,我们可以看出,GitHub的认证方式已经变成了每个repo设置自己单独的认证,相互之间完全独立,但GitLab不是,我tm就觉得这个多余,还是GitLab的方式简单粗暴~~~~