[git push error] remote: Support for password authentication was removed on August 13, 2021.

1. git push 报错

自从 2021-08-13 之后,Github 将不再支持使用 “用户名 + 密码” 的方式提交代码,执行 git push 之后将会看到如下错误。

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.

目前支持的方式有这些:OAuthSSH Key 或者 GitHub App installation token

2. 使用 SSH Key

SSH Key 的方式首先需要在本地生成一个 SSH Key 密钥,然后将在本地生成的一个公钥添加到 Github 中,这样两端就有加密和解密的工具,实现对数据的加密传输和解密的过程。

2.1. 生成密钥

有两种密钥的生成算法分别为 rsaed25519,推荐使用 ed25519。两者的区别的优缺点可以参考这篇文章 《ssh-key-ed25519-vs-rsa》
[注]:以下命令在 Windows 同样可以使用。
(1) 生成密钥之前确保你的 git 配置好了用户名和邮箱,若没有首先需要配置,使用如下命令:

$ git config --global user.name "你的用户名"
$ git config --global user.email "你的邮箱"

(2) 生成 ed25519 类型的密钥:
命令:

ssh-keygen -t ed25519 -C "你的邮箱"

示例(下面会打印密钥的默认保存目录):

imaginemiracle:~$ ssh-keygen -t ed25519 -C "[email protected]"

Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/imaginemiracle/.ssh/id_ed25519): # 输入回车选择默认密钥保存目录
Enter passphrase (empty for no passphrase): # 输入回车
Enter same passphrase again: # 输入回车
Your identification has been saved in /home/imaginemiracle/.ssh/id_ed25519
Your public key has been saved in /home/imaginemiracle/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:gPyj8hLrqxTtk7e48x4P5Y7o2bGITbWCRTVy8CTziis [email protected]
The key's randomart image is:
+--[ED25519 256]--+
|   =.=           |
|   .X..          |
|   .oo.          |
|  + .. .         |
| o + .o.S        |
|  B o.+.         |
|E+.O.* .         |
|o *+X X          |
|.++@*B o         |
+----[SHA256]-----+

(3) 在密钥生成的目录中查看密钥

imaginemiracle:~/.ssh$ pwd
/home/imaginemiracle/.ssh
imaginemiracle:~/.ssh$ ls
id_ed25519  id_ed25519.pub

(4) 将公钥中的信息添加到 Github
在这里插入图片描述
(5) 切换 httpsssh 方式上传

# 查看当前传输方式
imaginemiracle:~$ git remote -v
origin	https://github.com/ImagineMiracle-wxn/rvlinux_IM.git (fetch)
origin	https://github.com/ImagineMiracle-wxn/rvlinux_IM.git (push)

# 切换为 ssh
imaginemiracle:~$ git remote set-url origin [email protected]:ImagineMiracle-wxn/rvlinux_IM.git

# 查看当前传输方式
imaginemiracle:~$ git remote -v
origin	[email protected]:ImagineMiracle-wxn/rvlinux_IM.git (fetch)
origin	[email protected]:ImagineMiracle-wxn/rvlinux_IM.git (push)

(6) 重新 push

imaginemiracle:~$ git push origin master

到此已解决完毕

猜你喜欢

转载自blog.csdn.net/qq_36393978/article/details/127921780