GitHub Push 报错:Please use a personal access token instead

 

2021-08-13

GitHub

今天在提交 GitHub 其中一个仓库时,出现提示remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

从提示打开链接后发现是因为 GitHub 从 2021 年 08 月 13 日起不再支持在终端使用密码验证所致。奇怪的是按照文章内的说明使用 HTTPS 也是可以的:

1
What you need to do today
2
3
- For developers, if you are using a password to authenticate Git operations with GitHub.com today, **you must begin using a personal access token over HTTPS (recommended) or SSH key by August 13, 2021, to avoid disruption.** If you receive a warning that you are using an outdated third-party integration, you should update your client to the latest version.
4
- For integrators, you must authenticate integrations using the web or device authorization flows by August 13, 2021, to avoid disruption. For more information, see Authorizing OAuth Apps and the announcement on the developer blog.

但这边使用 HTTPS 还是出现报错:

Terminal window
1
git remote -v
2
origin https://github.com/immwind/logseq.git (fetch)
3
origin https://github.com/immwind/logseq.git (push)

解决

不过既然知道了原因,先改用 SSH key 试下:

Terminal window
1
git remote set-url origin [email protected]:immwind/logseq.git

设置完成后 push 成功。

进阶

设置的时候发现双因素认证还没启用,也一并设置了。

启用双因素认证

登陆 GitHub 后,点击头像选择Settings -> Security & analysis,后面按提示操作即可。

免密登录

此外正常情况下使用 ssh 方式需要输入密码,可以通过配置 ssh-keygen 实现免密登录:

Terminal window
1
cd ~/.ssh
2
# 生成 key
3
ssh-keygen -t ed25519 -C "[email protected]"
4
# 拷贝 key 到剪贴板(mac OS)
5
cat id_rsa.pub | pbcopy

然后在 GitHub 点击头像选择Settings -> SSH and GPG keys 粘贴即可。

参考