github ssh提交代码,解决443拒绝连接错误
更新 2023-9-18:
在gitbash中执行如下命令,报错:
git clone https://github.com/kinglong198404/klcms.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 对于 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
解决方案:生成新的Ed25519密钥对替代原来的rsa密钥对。
ssh-keygen -t ed25519 -C "kinglong198404"