Loading

github-change-https-to-ssh

吐槽

自从用了FQ软件之后,git clone或者git push等需要远程连接Github的操作就总是出现各种奇奇怪怪的问题,经过各种排查之后发现是代理没配置好。

我试过关闭ClashSystem Proxy,或者将System Proxyhttp改成PAC模式等等各种方法,都是一会儿好了一会儿又不行,真是烦不胜烦。

后来我无意间发现有人说SSH协议就不会跟Clash冲突,好像是SSH因为使用的传输协议跟HTTPS不同,具体差异见[1][2]

SSH密钥生成及使用[3]

  1. 查看电脑上是否已经存在SSH密钥,如果有了请跳过第二步
ls  ~/.ssh
# 我的电脑上已经有了以下密钥文件
├── id_ed25519
├── id_ed25519.pub
├── id_rsa
├── id_rsa.pub
  1. 生成SSH密钥
ssh-keygen -t ed25519 -C "your_email@example.com" #注意不要输入密码,将公钥添加到Github即可。
  1. 启动ssh-agent
Set-Service -Name ssh-agent -StartupType automatic # windows powershell

输入Get-Service ssh-agent查看是否启动成功,如果显示stopped就手动启动[4]一下吧。

image

  1. ssh密钥添加到ssh-agent
cd ~\.ssh\
ssh-add id_ed25519
  1. Github—> Settings—>SSH and GPG keys添加一个SSH key,名称无所谓,内容为id_ed25519.pub里的全部内容。

image-20230313161350516

  1. 工作完成🎉

参考资料


  1. git传输时使用的两种协议ssh和http的区别_git http_吨吨不打野的博客-CSDN博客 ↩︎

  2. git传输时使用的两种协议ssh和http的区别_git http_吨吨不打野的博客-CSDN博客 ↩︎

  3. 使用 SSH 连接 GitHub_ssh github_HZ_Samuel的博客-CSDN博客 ↩︎

  4. Install SSH-Agent and SSH-Add to Powershell ↩︎

posted @ 2025-02-27 08:00  ZilongLi  阅读(14)  评论(0)    收藏  举报