git操作出错显示fatal: unable to access ‘https://github.com/xxxx/xxxx.git/‘: SSL certificate problem:

git操作通过https链接从Github克隆仓库到本地总报错(Windows11)并且重新设置ssh key也没用的情况下

每次操作完git clone都显示如下内容
Cloning into ‘xxxx’…
fatal: unable to access ‘https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git/’: SSL certificate problem: unable to get local issuer certificate
包括git push以后也同样报错fatal:unable to…
这里提供一种解决错误的办法,符合条件即可使用

二者解决方式很接近,都是将后面粘贴的地址进行一些改动,所以不重复赘述,只说git clone时报错的解决办法。

$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
Cloning into 'YOUR-REPOSITORY'...
fatal: unable to access 'https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git/': SSL certificate problem: unable to get local issuer certificate

当时网上很多操作都试过,大部分都是告诉我重新设置ssh key,但是我也配置过很多次,都仍然报错,后面自己通过Github官方文档查到了问题根源所在。
解决办法:
参考文档:
权限被拒绝(公钥)
SSH故障排除
本人是Windows11操作系统
先通过尝试尝试连接到 git@github.com 来检查使用的密钥:
在git bash中输入以下命令:

ssh -vT git@github.com

然后会出现一长串内容,我这里只留关键的几行:

OpenSSH_9.1p1, OpenSSL 1.1.1s  1 Nov 2022
debug1: Reading configuration data /c/Users/xxxxx/.ssh/config
debug1: /c/Users/89443/.ssh/config line 1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to ssh.github.com [20.205.243.160] port 443.
debug1: Connection established.
[ssh.github.com]:443 / (none)
debug1: client_input_hostkeys: searching /c/Users/89443/.ssh/known_hosts2 for [ssh.github.com]:443 / (none)
debug1: client_input_hostkeys: hostkeys file /c/Users/89443/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: no new or deprecated keys from server
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi kxjh990528! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2104, received 2344 bytes, in 0.6 seconds
Bytes per second: sent 3488.6, received 3886.5
debug1: Exit status 1

可以看到其中几行
端口号
这里显示port 443,表示我们当前链接到Github是通过端口443进行链接。一般网络上提供的方法基本都是通过默认端口22进行链接,改端口太麻烦了于是我参考了官方文档SSH故障排除选择了一种更简捷有效的办法进行链接。
在 HTTPS 端口使用 SSH
有时,防火墙会完全拒绝允许 SSH 连接。
如果无法选择使用具有凭据缓存的 HTTPS 克隆,可以尝试使用通过 HTTPS 端口建立的 SSH 连接克隆。
大多数防火墙规则应允许此操作,但代理服务器可能会干扰。
输入以下命令:

$ ssh -T -p 443 git@ssh.github.com

若出现

> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.

则证明链接成功未被防火墙干扰。
要测试通过 HTTPS 端口的 SSH 是否可行,请运行以下 SSH 命令:

$ git clone ssh://git@ssh.github.com:443/YOUR-USERNAME/YOUR-REPOSITORY.git

注意:端口 443 的主机名为 ssh.github.com,而不是 github.com。
就是说把刚才的

$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git

改成

$ git clone ssh://git@ssh.github.com:443/YOUR-USERNAME/YOUR-REPOSITORY.git

即可使用。

Host github.com
Hostname ssh.github.com
Port 443
User git

如果还是不行请继续参考官方文档指南权限被拒绝(公钥)

  • 7
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值