V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ryougifujino
V2EX  ›  问与答

Mac 上如何 git clone ssh 协议的时候也走代理?

  •  1
     
  •   ryougifujino · 2020-02-25 20:08:55 +08:00 · 4390 次点击
    这是一个创建于 1515 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前通过配置

    git config --global http.proxy 和

    git config --global https.proxy

    使得 http/https 协议 clone 时是走代理了,但是 ssh 还是直连。该如何设置呢?

    12 条回复    2020-02-27 16:57:58 +08:00
    Jaosn
        1
    Jaosn  
       2020-02-25 20:13:52 +08:00
    export https_proxy=http://127.0.0.1:8888;export http_proxy=http://127.0.0.1:8888;export all_proxy=socks5://127.0.0.1:8889
    hguandl
        2
    hguandl  
       2020-02-25 20:14:44 +08:00
    .ssh/config:

    Host github.com
    ProxyCommand=nc -X 5 -x 127.0.0.1:1080 %h %p

    如果全部都想走代理就把 Host github.com 换成 Host *

    详见 https://gist.github.com/bynil/2126e374db8495fe33de2cbc543149ae
    ryougifujino
        3
    ryougifujino  
    OP
       2020-02-25 20:47:08 +08:00
    @hguandl #2 你好,首先谢谢你的回答。但我配置之后为什么就提示这个了呢?没配置之前是可以的。
    nc: read failed (0/3): Broken pipe
    ssh_exchange_identification: Connection closed by remote host
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
    ryougifujino
        4
    ryougifujino  
    OP
       2020-02-25 21:44:10 +08:00
    @hguandl #2 可以了,再次感谢。ProxyCommand=nc -X 5 -x 127.0.0.1:1080 %h %p,这句话实际上是指向的 socks5,而我 socks5 的端口是 1081,改了就可以了。
    statement
        5
    statement  
       2020-02-25 21:56:30 +08:00 via iPhone
    你给终端配一个代理不就行了
    Smilencer
        6
    Smilencer  
       2020-02-25 22:03:12 +08:00
    # proxy
    export http_proxy=socks5://127.0.0.1:10802
    export https_proxy=$http_proxy
    CEBBCAT
        7
    CEBBCAT  
       2020-02-25 22:34:43 +08:00
    这个问题不简单,但也不是搜不到。
    cat .ssh/config
    Host github.com
    HostName github.com
    User git
    # 走 HTTP 代理
    # ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080
    # 走 socks5 代理(如 Shadowsocks )
    ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
    xiri
        8
    xiri  
       2020-02-25 23:16:29 +08:00
    你需要配置 ssh 代理
    snowy0723
        9
    snowy0723  
       2020-02-26 00:29:51 +08:00 via Android
    再提供一个方法,用 proxychains.
    Kobayashi
        10
    Kobayashi  
       2020-02-26 00:59:10 +08:00 via Android
    Mellow,Surge 直接 TUN 无感知拦截。更狠的还有 Proxifier 内核模块拦截,代理。
    lbyo
        11
    lbyo  
       2020-02-27 16:53:42 +08:00
    @CEBBCAT #7
    ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
    ProxyCommand=nc -X 5 -x 127.0.0.1:1080 %h %p

    -v 和 -X 5 的区别是什么呢
    lbyo
        12
    lbyo  
       2020-02-27 16:57:58 +08:00
    @lbyo #11 https://man.openbsd.org/nc.1#SYNOPSIS
    找到 config 文档了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2798 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:09 · PVG 21:09 · LAX 06:09 · JFK 09:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.