栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

git push出现 “fatal: 发送请求时出错。”的一种特殊情况

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

git push出现 “fatal: 发送请求时出错。”的一种特殊情况

问题描述

前提

ssh -T git@github.com 命令连接正常;

git clone、git pull 正常,github页面 `Settings/SSH and GPG keys` 确认已添加过本地ssh公钥。

注:git clone 出现类似问题的,可以考虑先移步git clone出现 fatal: unable to access 'https://github.com/...'的解决办法(亲测有效)_明天也要加油鸭的博客-CSDN博客

$ ssh -T git@github.com
Hi birdflyi! You've successfully authenticated, but GitHub does not provide shell access.

问题

git push 失败,提示fatal: 发送请求时出错,并报告不再支持密码认证方式,需要使用personal access token替代密码认证方式(然而前面已确认github页面添加过本地的ssh公钥)。

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git push --set-upstream origin main
fatal: 发送请求时出错。
fatal: 请求被中止: 未能创建 SSL/TLS 安全通道。
fatal: 发送请求时出错。
fatal: 请求被中止: 未能创建 SSL/TLS 安全通道。
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: Authentication failed for 'https://github.com/birdflyi/Research-Methods-of-Cross-Science/'

remote报错:2021年8月13日,移除了对密码验证方式的支持。请改用个人访问令牌。

官方的解释:https://github.blog/changelog/2021-08-12-git-password-authentication-is-shutting-down/

已有相关博客解释说明此变化,并给出了配置github上的ssh Keys的方法[1]:GitHub不再支持密码验证解决方案:SSH免密与Token登录配置 - 爱码网

此博客还包含使用令牌的好处说明:GitHub不再支持密码验证解决方案:SSH免密与Token登录配置 - 爱码网

问题特征

特殊情况的特征在于:git remote -v 显示配置的url是http或https协议的,而配置的ssh需要使用git@github.com形式的ssh协议url。

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote -v
origin  https://github.com/birdflyi/Research-Methods-of-Cross-Science (fetch)
origin  https://github.com/birdflyi/Research-Methods-of-Cross-Science (push)
解决方案

综上,github的ssh Keys配置(详见[1]不再赘述)没有问题的情况下,将remote的url改成ssh所需的git@github.com形式即可。

即:

$ git remote remove origin 

$ git remote add origin git@github.com:birdflyi/Research-Methods-of-Cross-Science

实践中会有一些额外的操作才能使用默认的 git push 命令:

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote -v
origin  https://github.com/birdflyi/Research-Methods-of-Cross-Science (fetch)
origin  https://github.com/birdflyi/Research-Methods-of-Cross-Science (push)

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote remove origin

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote add origin git@github.com:birdflyi/Research-Methods-of-Cross-Science

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote -v
origin  git@github.com:birdflyi/Research-Methods-of-Cross-Science (fetch)
origin  git@github.com:birdflyi/Research-Methods-of-Cross-Science (push)

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git push
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main


Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git push --set-upstream origin HEAD:main
Everything up-to-date
branch 'main' set up to track 'origin/main'.

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git push
Everything up-to-date

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/964075.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号