GitHub仓库push报错remote: Support for password authentication was removed on August 13, 2021.

发现GitHub项目从2021年8月13日开始已经不能使用用户名和密码push代码了,搜索了下,有以下两种方法可以尝试,记录一下:

ssh 方式

  1. 先在电脑上生成ssh的加密公私钥,使用如下命令, 命令中要将-C后面的参数设置为自己的github账号邮箱,-f后面的参数为私钥对应的存储位置。 输入命令之后,如果确认路径没有问题就按回车确认了

ssh-keygen -t ed25519 -C '你的github账号邮箱' -f ~/.ssh/id_rsa_github
  1. 将上一步生成的公钥配置在GitHub账号中,进入GitHub官网,在右上角依次点击自己的头像-Settings-->SSH and GPG keys--- New SSH key, 将生成的与私钥在同一个文件夹目录的公钥id_rsa_github.pub 的内容粘贴并保存

  1. 如果有多个git账号的话,再在~/.ssh/config 文件中添加下面的配置。(如果只有一个git账号,此步可以省略)

Host github.com
port 22
User git
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github

上面的IdentityFile就是第1步中生成的密钥的位置,其余保持一致就可以了

  1. 设置仓库的URL, 使用git remote set-url origin 设置url, 注意将命令中的[github用户名]和[github仓库名]替换成自己的信息

git remote set-url origin git@github.com:[github用户名]/[github仓库名].git

# 设置完后可以通过git remote -v 确认是否有变化
git remote -v
  1. 经过上面的配置,就可以成功使用git push origin master来提交代码了

使用personal access token

  1. 首先去GitHub 生成personal access token, 进入github官网,在右上角依次点击自己的头像-Settings-->Developer settings--> Personal access tokens-->Tokens (classic), 再选择Generate new token, 点击 Generate new token (classic) 进入生成token的页面,填写token描述、有效期、授权等信息,然后点击Generate token最终生成了一个token。

  1. 设置仓库的URL, 使用git remote set-url origin 设置url, 注意将命令中的[生成的token]、[github用户名]、[github仓库名]替换成自己的信息

git remote set-url origin https://[生成的token]@github.com/[github用户名]/[github仓库名].git
  1. 经过上面的配置,就可以成功使用git push origin master来提交代码了

参考

  1. https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

  1. https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories#changing-a-remote-repositorys-url

  1. https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值