V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
beginor
V2EX  ›  GitHub

无法使用 [email protected] 推送/拉取代码, 是抽风了还是被墙了?

  •  
  •   beginor ·
    beginor · 2022-04-25 08:20:15 +08:00 · 4045 次点击
    这是一个创建于 703 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这几天突然发现无法使用 [email protected]:user/repo 推送 /拉取代码了, 一开始以为是 ssh_key 过期的问题, 重新生成了新的 ssh_key , 发现还是不行, 提示如下:

    git status
    On branch master
    Your branch is ahead of 'origin/master' by 1 commit.
      (use "git push" to publish your local commits)
    
    nothing to commit, working tree clean
    
    git push
    ssh: connect to host github.com port 22: Operation timed out
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    
    第 1 条附言  ·  2022-04-25 09:15:21 +08:00
    感谢完成的 V 友,4 楼和 7 楼的方法都可以, 不过 4 楼的方法要说明一下,先用 `brew install connect` 安装 connect 命令, 再有就是必须是 http/https 代理。

    没想到 github 也有这待遇, 大家且用且珍惜!
    第 2 条附言  ·  2022-04-26 10:00:04 +08:00

    自己的梯子结实的话,可以这样配置 ~/.ssh/config :

    Host github.com
      IdentityFile ~/.ssh/github_rsa
      HostName github.com
      Port 22
      User git
      ProxyCommand nc -X 5 -x 127.0.0.1:10086 %h %p
    

    nc -X 5 -x 127.0.0.1:10086 表示通过 127.0.0.1:10086 的 socks5 代理

    如果自己的梯子不结实的话或者没梯子(在V2好像是废话),可以暂时这样配置 ~/.ssh/config :

    Host github.com
      IdentityFile ~/.ssh/github_rsa
      Hostname ssh.github.com
      Port 443
    

    这种方式能用多久, 看墙的心情吧

    第 3 条附言  ·  2022-05-25 09:16:31 +08:00

    貌似使用 443 端口方式的配置已经失效, 返回内容为:

    ssh: connect to host ssh.github.com port 443: Connection refused
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

    只能通过梯子拉取代码了么?

    28 条回复    2022-06-09 13:22:27 +08:00
    villivateur
        1
    villivateur  
       2022-04-25 08:24:06 +08:00 via Android
    被墙了
    ZE3kr
        2
    ZE3kr  
       2022-04-25 08:36:15 +08:00 via iPhone
    据说 443 端口也可以 ssh ,楼主试试
    beginor
        3
    beginor  
    OP
       2022-04-25 08:38:11 +08:00
    @ZE3kr 很早就就不能用 https 推送了,后来才迁移到 ssh 的
    wszzh
        4
    wszzh  
       2022-04-25 08:40:52 +08:00
    遇到一样的情况,后来配置了 SSH 代理解决了。https://www.wuyiting.cn/blog/Correct%20way%20to%20set%20git%20proxy
    windplume
        5
    windplume  
       2022-04-25 08:48:34 +08:00
    我昨天是改了 http(s).proxy 才能连上
    Hack3rHan
        6
    Hack3rHan  
       2022-04-25 08:50:38 +08:00 via iPhone
    配个代理就知道是不是墙了,而且 Operation timed out 已经很明显了。
    MrCurly
        7
    MrCurly  
       2022-04-25 08:53:48 +08:00   ❤️ 2
    Host github.com
    Hostname ssh.github.com
    Port 443
    MrCurly
        8
    MrCurly  
       2022-04-25 08:53:57 +08:00
    试试
    tinkerer
        9
    tinkerer  
       2022-04-25 09:03:06 +08:00
    ssh 流量是墙重点关照对象
    beginor
        10
    beginor  
    OP
       2022-04-25 09:09:00 +08:00
    @MrCurly 谢谢, 这个确实可行, 且用且珍惜
    beginor
        11
    beginor  
    OP
       2022-04-25 09:11:55 +08:00
    @wszzh 谢谢, 这个也可行, 必过必须是 http/https 代理, 不能是 socks5 代理
    mschultz
        12
    mschultz  
       2022-04-25 09:25:29 +08:00
    Host github.com
    Hostname ssh.github.com
    Port 443
    User git
    ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p

    SOCKS5 代理是可以的。我这里的 nc 是 macOS 自带的 /usr/bin/nc, 别的系统上的 netcat 可能参数稍微不同但应该大同小异。
    AllenHua
        13
    AllenHua  
       2022-04-25 09:28:03 +08:00   ❤️ 1
    毛遂自荐了属于是 https://www.v2ex.com/t/843383#reply47
    fzls
        14
    fzls  
       2022-04-25 09:34:37 +08:00
    用这个,感觉是快开会了,墙的强度加大了
    前天家里电脑也遇到了,当时在 Stack Overflow 找到个解决方案 https://stackoverflow.com/a/52817036
    与 7 楼基本一样
    silentsky
        15
    silentsky  
       2022-04-25 09:38:05 +08:00
    昨天我也遇到这个问题
    beginor
        16
    beginor  
    OP
       2022-04-25 09:49:34 +08:00 via Android
    @mschultz
    @AllenHua

    学习了, 回去就把 connect 删了 😂
    jdjingdian
        17
    jdjingdian  
       2022-04-25 09:50:45 +08:00
    最近一直遇到 ping 不通 github.com ,用站长工具多地点 ping 发现全国很多地方都 ping 不通,有个别 ip 是可以 ping 通,我就先写 hosts 来用了
    wszzh
        18
    wszzh  
       2022-04-25 09:53:58 +08:00
    @beginor socket 代理协议可以的哦,改参数 -H 改为 -S ,下面是我的配置。
    Host github.com
    User git
    ProxyCommand connect -S 127.0.0.1:7890 %h %p
    详情可以参照这个帖子 https://v2ex.com/t/841032#reply17
    wszzh
        19
    wszzh  
       2022-04-25 09:55:37 +08:00
    总喜欢把 socks 打成 socket 😂
    AllenHua
        20
    AllenHua  
       2022-04-25 10:15:25 +08:00
    @beginor #16 macOS 和 大部分 Linux Distro 都自带 /usr/bin/nc 的
    jsdi
        21
    jsdi  
       2022-04-25 10:51:47 +08:00
    +1 ,昨天突然不行了,重装了 git/更新 ssh 也没有解决,发现是被墙了,最终设置 http 代理成功解决了
    yaott2020
        22
    yaott2020  
       2022-04-25 11:18:35 +08:00 via Android
    github 就挂梯子吧,与其去找 ip 填 hosts ,梯子反而好使
    ccyu220
        23
    ccyu220  
       2022-04-25 11:27:39 +08:00
    @yaott2020 全局梯子也没用,基本都是 443
    haoliang
        24
    haoliang  
       2022-04-25 18:27:07 +08:00
    同!
    今天下午移动网络+梯子,git 走 ssh ( 22 端口)死活不通;换到联通+梯子就可以了
    beginor
        25
    beginor  
    OP
       2022-05-25 09:17:21 +08:00
    @MrCurly 这种配置已经失效了
    MrCurly
        26
    MrCurly  
       2022-05-25 10:14:14 +08:00
    @beginor 我刚试了下还是好用的
    MrCurly
        27
    MrCurly  
       2022-05-25 10:18:13 +08:00
    @beginor 你不是用的梯子么。。。用梯子吧,别浪费生命了
    RedBeanIce
        28
    RedBeanIce  
       2022-06-09 13:22:27 +08:00
    我梯子 720p 油管都不卡,但是 git ssh 拉取代码就是 20k/s ,真的绝了。

    求一个解决办法
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   941 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 21:00 · PVG 05:00 · LAX 14:00 · JFK 17:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.