【问题标题】:How to configure git to clone repo from github behind a proxy server如何配置 git 从代理服务器后面的 github 克隆 repo
【发布时间】:2016-11-14 21:03:59
【问题描述】:

所有, 我在我的 Ubuntu 上的 github 上遇到了一个关于 git 的问题。 我已经通过git config --global http.proxy proxyserver:port 配置了代理设置 但是当我输入 git clone git@github.com:myusername/example.git 时,我得到了以下信息 错误:ssh: connect to host github.com port 22: Connection timed out fatal: The remote end hung up unexpectedly 我应该怎么办? 谢谢 史蒂文

【问题讨论】:

  • 您正在尝试连接 ssh,它不使用 HTTP 代理设置。您可能需要在 Github 上使用 HTTP 或 HTTPS URL。
  • 也许this 能帮上忙。
  • 我使用 https url 来克隆 repo,它可以工作。

标签: git ubuntu github ssh


【解决方案1】:

我按照以下步骤从公司代理后面访问 git 存储库。此方法适用于使用诸如“git://something.git”之类的 git URL 的 git 存储库; 对于使用诸如“http://something.git”之类的 http URL 的 git 存储库,请改用此 link 的公认答案。

此版本使用开瓶器并设置代理所需的用户名和密码。

安装开瓶器(Ubuntu)

sudo apt-get install corkscrew

创建包含您的代理用户名和密码的凭据文件

echo "username:password" > ~/.corkscrew-auth

在我的情况下,凭据如下所示

domain\username:password

安全的身份验证文件

chmod 600 ~/.corkscrew-auth

创建开瓶器包装脚本 ~/scripts/corkscrew.wrapper

#!/bin/sh
exec corkscrew PROXY_IP_ADDRESS PROXY_PORT $* ~/.corkscrew-auth

使脚本可执行

chmod +x ~/scripts/corkscrew.wrapper

配置 git

git config --global core.gitproxy ~/scripts/corkscrew.wrapper

测试是否可以克隆存储库

git init
git clone git://SOME_GIT_REPOSITORY_ADDRESS

如果你想清理你刚刚做的 git 配置

git config --global --unset core.gitproxy

【讨论】:

    【解决方案2】:

    第 1 步:安装开瓶器

    $ sudo apt-get install corkscrew
    

    第 2 步:编写一个名为 git-proxy.sh 的脚本并添加以下内容

    #!/bin/sh
    
    exec corkscrew <name of proxy server> <port> $*
    
    # <name_of_proxy_server> and <port> are the ip address and port of the server
    # e.g. exec corkscrew 192.168.0.1 808 $*
    

    第 3 步:使脚本可执行

    $ chmod +x git-proxy.sh
    

    第四步:通过设置环境变量为 GIT 设置代理命令

    $ export GIT_PROXY_COMMAND="/<path>/git-proxy.sh"
    

    现在使用git命令,比如

    git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    

    【讨论】:

    猜你喜欢
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 2018-09-14
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    相关资源
    最近更新 更多