如何设置 Git 通过代理
我想在工作中连接GitHub,需要通过http代理。我可以使用以下命令使用 cURL 访问 FTP
curl -v -g --ftp-pasv --upload-file MYFILE --proxy PROXYADDRESS:PROXYPORT --proxy-ntlm --proxy-user WINDOWSDOMAIN\WINDOWSUSER:WINDOWSPASSWORD ftp://FTPUSER:FTPPASS @FTPURL/
,我还无法为 Git 提供等效的设置。
我尝试按照 cygwin 下 通过 Draconian 代理使用 Github 上的说明进行操作。
我已经安装了 corkscrew 并尝试通过 SSH 连接到 GitHub
ssh github.com
,否则
ssh ssh.github.com
我会返回
ssh:无法解析主机名 ssh.github.com:提供主机名或服务名,或未知。
我尝试过设置 http 和 https 代理。
这是 git --config -l 的输出,
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=C:/Program Files/Git/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
user.name=Peter Wilkinson
[email protected]
github.user=ProggerPete
github.token=shouldprobablykeepthissecret
http.proxy=http://somedomain\someuser:[email protected]:80
https.proxy=http://somedomain\someuser:[email protected]:80
我也运行了
export https_proxy=http://somedomain\someuser:[email protected]:80
export http_proxy=http://somedomain\someuser:[email protected]:80
set https_proxy=http://somedomain\someuser:[email protected]:80
set http_proxy=http://somedomain\someuser:[email protected]:80
然后尝试克隆并获取。
$ git clone https://[email protected]/project/JavaScript-Maven-Plugin.git
Cloning into JavaScript-Maven-Plugin...
Password:
error: The requested URL returned error: 407 while accessing https://ProggerPet
@github.com/project/JavaScript-Maven-Plugin.git/info/refs
fatal: HTTP request failed
在我看来,我无法通过代理进行身份验证。不过,我使用的登录名和密码与通过 cURL 的 FTP 相同。
我怎样才能连接?
I want to connect to GitHub at work and need to get through the http proxy. I am able to get out for FTP using cURL using the command
curl -v -g --ftp-pasv --upload-file MYFILE --proxy PROXYADDRESS:PROXYPORT --proxy-ntlm --proxy-user WINDOWSDOMAIN\WINDOWSUSER:WINDOWSPASSWORD ftp://FTPUSER:FTPPASS@FTPURL/
I've so far not been able to provide equivalent settings for Git.
I tried following instructions on Using Github Through Draconian Proxies under cygwin.
I've got corkscrew installed and tried to SSH to GitHub
ssh github.com
or
ssh ssh.github.com
I get back
ssh: Could not resolve hostname ssh.github.com: hostname nor servname provided, or not known.
I've tried setting the http and https proxy.
Here is the output from git --config -l
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=C:/Program Files/Git/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
user.name=Peter Wilkinson
[email protected]
github.user=ProggerPete
github.token=shouldprobablykeepthissecret
http.proxy=http://somedomain\someuser:[email protected]:80
https.proxy=http://somedomain\someuser:[email protected]:80
I've also run
export https_proxy=http://somedomain\someuser:[email protected]:80
export http_proxy=http://somedomain\someuser:[email protected]:80
set https_proxy=http://somedomain\someuser:[email protected]:80
set http_proxy=http://somedomain\someuser:[email protected]:80
I then try and clone and get.
$ git clone https://[email protected]/project/JavaScript-Maven-Plugin.git
Cloning into JavaScript-Maven-Plugin...
Password:
error: The requested URL returned error: 407 while accessing https://ProggerPet
@github.com/project/JavaScript-Maven-Plugin.git/info/refs
fatal: HTTP request failed
This looks to me like I'm failing authentication with the proxy. However I'm using the same login and pass that works for FTP via cURL.
How can I get connected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我通常只需要设置:(
注意
https_proxy
指的是相同的 http,而不是 https,代理地址)另请参阅“无法在 git 上获取 Http 工作”。
I usually only need to set:
(note the
https_proxy
refers to the same http, not https, proxy address)See also "Cannot get Http on git to work".
您可以将代理信息放入 ~/.curlrc 中:
You can put proxy information in your ~/.curlrc:
您不太可能能够通过代理通过 ssh 隧道连接到 github。然而,由于 github 为其所有存储库提供了 https url,因此您可以推送到不需要 ssh 的地方。如果您已经签出存储库,则可以更改使用的 url
(如果不需要推送访问,请跳过第二行)。
这与 VonC 提到的设置环境变量 (https_proxy) 一起将允许通过代理进行访问。
You are unlikely to be able to get ssh to github tunnelled through your proxy. However as github provides https urls for all their repositories and you can push to that you don't need ssh. If you already have a repository checked out, you can change the url used with
(skip the second line if you do not need push access).
This, along with setting the environment variables (https_proxy) as mentioned by VonC will enable access via your proxy.
经过多次头痛之后,我终于偶然发现了 http://cntlm.sourceforge.net/。它是一个理解 ntlm 身份验证的代理代理。
我安装了它并告诉它有关http代理的信息。然后将 git 指向 CNTLM,一切就开始工作了。
我发现这样做非常令人沮丧,所以希望这能帮助其他处于同样情况的人。
After much head bashing I finally stumbled across http://cntlm.sourceforge.net/. It's a proxy proxy that understands ntlm authentication.
I installed it and told it about the http proxy. Then pointed git at CNTLM and it all started working.
I found getting this going very frustrating so hopefully this will help someone else in the same situation.