问题描述

今天提交内容到GitHub的时候报了如下错误:

1
2
3
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/yx-hh/yx-hh.github.io.git/': The requested URL returned error: 403

问题原因

如上面👆提示信息所诉,GitHub对密码验证的支持只到8月13日,后面需要使用个人访问token简称PAT。官方解释是更安全。

之前提交时输入过用户名和密码,但是这种方式不支持了!

是不是有点疑惑🤔,如何切换为token登入?

问题解决办法

如果想通过Git连接到GitHub,有两种方式:HTTPS或者SSH认证。

我之前使用的是HTTPS的方式,输入用户名和密码,git会根据我之前访问成功之后生成的证书继续访问。不成功就报错。

通过HTTPS连接

官网说明信息如下:

1
When you git clone, git fetch, git pull, or git push to a remote repository using HTTPS URLs on the command line, Git will ask for your GitHub username and password. When Git prompts you for your password, enter your personal access token (PAT) instead. Password-based authentication for Git is deprecated, and using a PAT is more secure. For more information, see "Creating a personal access token."

意思就是执行git操作的时候,会提示你填写GitHub用户名,你用个人token(PAT)替换密码就行,因为密码登入已经过时了。

即:

1
2
3
git clone <REMOTE_URL> 
username: <your GitHub username>
password: <your PAT>

现在还剩下两个问题:

1、生成PAT

生成方法,跟着官网一步步来,非常简单:link

2、操作git时弹出输入用户名和密码的提示

出现最开始提示语且没弹出让重新输入用户名和密码的原因是,(mac电脑举例)之前登入成功后MacOS已经帮你把生成的证书存入到它的钥匙串访问(Keychain Access)中了,需要删除原有的。两种删除操作的详情链接如下:link

方法一:在Keychain Access中搜索框中输入GitHub,把类型为Internet password的那一条数据删掉。再次操作git就会弹出输入用户名和密码的提示语了。

方法二:通过命令行删, 操作成功不会打印任何信息。

1
2
3
4
$ git credential-osxkeychain erase
host=github.com
protocol=https
> [Press Return]

通过SSH连接

link

参考链接

Authenticating with GitHub from Git