周凯,个人博客

  • 前端
  • 嵌入式
  • 工具
  • 后端
  • 随笔
个人记录
  1. 首页
  2. git
  3. 正文

Git问题:解决“ssh:connect to host github.com port 22: Connection timed out”

2024年 1月 25日 1028点热度 0人点赞 0条评论

问题

  • 错误提示: “ssh:connect to host github.com port 22: Connection timed out”

解决

  • 查询资料:原因可能是由于电脑的防火墙或者其他网络原因导致ssh连接方式 端口22被封锁。
  • 方法一:抛弃ssh连接方式,使用http连接。(我没有用)
    • git config --local -e
    • 将配置文件的url = git@github.com:username/repo.git一行改为:url = https://github.com/username/repo.git
  • 方法二:如果22号端口不行,那就换一个端口
    • 进入.ssh cd ~/.ssh
    • 创建一个config文件 vim config
    • 编辑文件内容
      Host github.com
      User git
      Hostname ssh.github.com
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/id_rsa
      Port 443
      Host gitlab.com
      Hostname altssh.gitlab.com
      User git
      Port 443
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/id_rsa
    • 保存退出
    • 检查是否成功 ssh -T git@github.com
    • 这里要根据它的提示操作,有个地方要输入yes
    • 再次运行 git push就可以推送成功了

🎯 拓展阅读提示

本文涉及的内容已同步至公众号后台,我会在那里分享更多深度内容和实用技巧

→ 点击关注:一行梦境

公众号二维码
本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2024年 1月 25日

周凯

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2022-现在 周凯,个人博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

蒙ICP备18004897号