github ssh提交代码,解决443拒绝连接错误

作者:陆金龙    发表时间:2022-03-11 22:39   

关键词:Failed to connect to github. com port 443  have the correct access rights  SA key with SHA-1 no longer allowed  github push  Please make sure you have the correct access rights and the repository exists  

更新 2023-9-18:

在gitbash中执行如下命令,报错:

git clone https://github.com/kinglong198404/klcms.git

 
fatal: unable to access 'https://github.com/kinglong198404/klcms.git/': Unknown SSL protocol error in connection to github.com:443
 
解决方案:(1)gitbash中执行 ssh-keygen -R github.com,更新客户端.ssh下的known_hosts文件中的密钥。(2)gitbash客户端切换到ssh模式:git remote set-url origin git@github.com:kinglong198404/spring-cloud-architect.git
 

更新 2022-7-30:

      处理报错 You're using an RSA key with SHA-1, which is no longer allowed. Please use a newer client or a different key type.

   GitHub 在 2022 年 3 月 15 日之后将不再支持 RSA 算法生成的密钥,原因是 RSA 不够安全,之前一直使用如下命令生成密钥对的:ssh-keygen -t rsa -C "邮箱"
 
  现在只要更改加密算法即可,可以选择 ed25519。
(以上解决方案来自CSDN博主「暗诺星刻」原创文章,链接:https://blog.csdn.net/wangpaiblog/article/details/124416005)

--------------------------------------------------------------------------------------------------------

github 对于 https 方式下载的仓库已经不支持直接 commit、push 等操作。因此需改为ssh模式进行。

1.生成密钥文件

打开 gitbash, 输入命令:

ssh-keygen -t rsa -C "kinglong198404" //kinlgong1984为我在github上的用户名

ssh-keygen -t ed25519 -C "kinglong198404"

命令行可能返回:

Generating public/private rsa key pair.
Enter file in witch to save the key(/Users/username/.ssh/id_rsa):

我们直接回车,命令行继续提示:

Enter passphrase(empty for no passphrase)

直接回车。

然后在C:\Users\Administrator\.ssh下生成了id_rsa和id_rsa.pub文件。

2.在 github 添加 ssh 密钥

(1)进入setting->SSH and GPG keys,点击按钮“New SSH key”

 

(2)拷贝id_rsa.pub文件的内容,粘贴到弹出界面的Key中。title可以不填。点击Add SSH key提交。

3.gitbash客户端切换到ssh模式

gitbash, 输入命令:git remote -v,可以看到目前是https模式。

执行以下命令切换到ssh模式(黄色背景部分改成您github项目的ssh地址):

$ git remote set-url origin git@github.com:kinglong198404/spring-cloud-architect.git

这样就可以在gitbash中正常commit和push了。

4.关于TortoiseGit设置ssh连接git仓库

使用 ssh-keygen  -t rsa  -C "username"产生的密钥,TortoiseGit中不能用。需配置ppk格式的私钥。

1)运行PuTTYgen,在Conversions菜单中点击Import key,选择一开始生成的私钥文件 id_rsa文件。

     点击Save private key 按钮,将其保存为.ppk文件。

2)打开Pageant,点击Add Key,选择前一步所保存的.ppk文件所在的位置即可。

3)以上配置完成后,使用TortoiseGit进行push,显示已成功。

5.报错correct access rights

Please make sure you have the correct access rights and the repository exists。

可能是密钥配置失效了(比如公钥被删除重新配置了一遍),上述流程重新来一遍。

参考:

https://blog.csdn.net/jiaming917/article/details/123419756

https://blog.csdn.net/yjw123456/article/details/119696726

6.报错 RSA key with SHA-1  no longer allowed 

You're using an RSA key with SHA-1, which is no longer allowed. Please use a newer client or a different key type.

解决方案:生成新的Ed25519密钥对替代原来的rsa密钥对。

ssh-keygen -t ed25519 -C "kinglong198404"

生成了id_ed25519和id_ed25519.pub两个文件。用id_ed25519.pub的内容重新去github设置。用id_ed25519生成ppk文件应用到在TortoiseGit上。