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 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 -T git@github.com

或者

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进行链接,因为22号端口被防火墙屏蔽,我参考了官方文档SSH故障排除选择了一种更简捷有效的办法进行链接。
在 HTTPS 端口使用 SSH
有时,防火墙会完全拒绝允许 SSH 连接。
如果无法选择使用具有凭据缓存的 HTTPS 克隆,可以尝试使用通过 HTTPS 端口建立的 SSH 连接克隆。
大多数防火墙规则应允许此操作,但代理服务器可能会干扰。
输入以下命令:

ssh -vT -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

还有一种办法:
如果不想每次多输入一个443,则可以直接在配置文件里修改端口。
在gitbash中输入:

vim ~/.ssh/config

这里打开的是~/.ssh/config配置文件,
将如下内容添加进~/.ssh/config文件中,意思就是将端口改成443

# Add section below to it
Host github.com
  Hostname ssh.github.com
  Port 443

保存退出,再次输入指令即可看到成功链接!
但是这个方案有效的前提是:
执行命令ssh -T -p 443 git@ssh.github.com后不再提示connection refused
如果还是不行请继续参考官方文档指南权限被拒绝(公钥)

### 解决 Git 访问 GitHubSSL 证书问题 当遇到 `fatal: unable to access 'https://github.com/git/git/': SSL certificate problem: unable to get local issuer certificate` 错误时,这通常是因为本地缺少有效的 CA (Certificate Authority) 证书或配置不当所致。 #### 方法一:更新系统中的CA证书包 对于基于Debian的Linux发行版(如Ubuntu),可以通过安装最新的ca-certificates软件包来解决问题: ```bash sudo apt-get update sudo apt-get install ca-certificates ``` 此命令将会更新系统的根证书库至最新版本[^1]。 #### 方法二:禁用SSL验证(仅限测试环境) 如果是在开发环境中临时绕过这个问题,则可以设置全局变量以跳过HTTPS请求的身份验证过程。请注意,在生产环境下不建议这样做因为存在安全隐患。 ```bash git config --global http.sslVerify false ``` 上述指令将告诉Git忽略所有的SSL认证错误并继续执行操作[^2]。 #### 方法三:手动下载并导入GitHubSSL证书 另一种解决方案是从浏览器导出当前受信任的GitHub服务器证书,并将其添加到Git使用的OpenSSL证书存储中去: 1. 打开网页浏览器访问 https://github.com/ 2. 查看网站的安全信息找到其公钥证书链 3. 将顶级颁发机构(CA)证书保存为PEM文件格式 4. 使用下面的命令让Git能够识别新加入的信任列表成员 ```bash export GIT_SSL_CAINFO=/path/to/certificate.pem ``` 这种方法适用于那些无法通过常规方式获取有效网络连接的情况下的特殊场景[^3]。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值