簡體   English   中英

git clone是否可以通過NTLM代理工作?

[英]Does git clone work through NTLM proxies?

我已嘗試使用export http_proxy=http://[username]:[pwd]@[proxy]git config --global http.proxy http://[username]:[pwd]@[proxy]

我無法讓它發揮作用。 看起來git使用Basic身份驗證:

Initialized empty Git repository in /home/.../.git/
* Couldn't find host github.com in the .netrc file, using defaults
* About to connect() to github.com port 8080 (#0)
*   Trying 10.... * Connected to github.com (10....) port 8080 (#0)
* Proxy auth using Basic with user '...'
> GET http://github.com/sunlightlabs/fiftystates.git/info/refs HTTP/1.1
Proxy-Authorization: Basic MD...
User-Agent: git/1.6.1.2
Host: github.com
Pragma: no-cache
Accept: */*
Proxy-Connection: Keep-Alive

< HTTP/1.1 407 Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to t
he Web Proxy filter is denied.  )
< Via: 1.1 ...
< Proxy-Authenticate: Negotiate
< Proxy-Authenticate: Kerberos
< Proxy-Authenticate: NTLM
< Connection: Keep-Alive
< Proxy-Connection: Keep-Alive
< Pragma: no-cache
< Cache-Control: no-cache
< Content-Type: text/html
< Content-Length: 4118
* The requested URL returned error: 407
* Closing connection #0
fatal: http://github.com/sunlightlabs/fiftystates.git/info/refs download error - The requested URL returned error: 407

Google搜索返回了混合且可能未更新的結果。 在某個地方,它說curl是(是?)在引擎蓋下使用,但它的選項(是?)硬連線到代碼中。 例如,

curl --proxy-ntlm --proxy ...:8080 google.com

工作,我想與git使用相同的選項。

我在這里需要一些更明確的答案:有沒有人通過Windows代理成功使用git? 哪個版本?

謝謝。

默認NTLM憑據

要使用默認的NTLM憑據,請提供空的用戶名和密碼

git config --global http.proxy https://:@proxy:port

ISA Server的防火牆客戶端

您可以使用Microsoft的ISA Server防火牆客戶端,而不是為git,npm等設置代理。 安裝后:

Start > Autostart > Microsoft Firewall Client Management

Settings tab > Manual specified ISA Server > proxy:port Web Browser tab > Uncheck "Enable web browser automatic configuration."

Git支持從版本1.7.10開始的NTLM代理身份驗證,相關提交是https://github.com/gitster/git/commit/dd6139971a18e25a5089c0f96dc80e454683ef0b

1.7.10 發布說明簡要提到它:

* HTTP transport learned to authenticate with a proxy if needed.

我已經成功地在我的工作場所使用代理進行了測試,這是NTLM並且需要用戶/通行證,您可以使用以下命令測試自己:

git config --global http.proxy http://user:password@proxy.com:port
git clone http://git.videolan.org/git/bitstream.git

問候,

克隆對我有用,但只能通過HTTP(因為我們的公司防火牆阻止了ssh / git協議):

$ export http_proxy="http://username:password@proxy:port/"
$ git clone http://github.com/sunlightlabs/fiftystates_site.git fifty
Initialized empty Git repository in /home/user/fifty/.git/
got e15f5192b923d8e87abaeb9406d0f4d80403da09
walk e15f5192b923d8e87abaeb9406d0f4d80403da09
got a78b792191f1cf5e961753dcfe05e9c809bdb0ed
got 76e6e86e72a0f998f7663da69ca49c457a302e27
walk 76e6e86e72a0f998f7663da69ca49c457a302e27
got 35b68a3b876fb90e73ba7a7eb51432e825ef2aa3
...

Github建議通過git://github.com/...克隆,但你必須手動將其更改為http://github.com/...

編輯:我正在使用git版本1.5.6.3。

希望有所幫助!

AndreaG(在上面的評論中)對我能找到的這個問題有唯一可接受的答案。 似乎Git只是不能使用NTLM代理,即使它真的應該因為cURL(它在下面使用)確實工作得很好。 為什么這個問題無法修復我不知道。 這似乎是一個相當普遍的問題。

完整的解決方案是使用ntlmaps充當代理的代理。 您需要做的就是從以下網址下載最新版本的應用程序: http//ntlmaps.sourceforge.net/

更改配置文件以包含您的身份驗證和代理詳細信息,然后將代理設置為新的本地代理:

git config --global http.proxy http://localhost:5865

我可以確認它工作得很好。 您不僅可以將它用於任何需要NTLM身份驗證但不提供完整NTLM支持的應用程序。

你也可以使用cntlm,

http://cntlm.sourceforge.net/

類似於ntlmaps但使用純C編寫的解決方案。它通過在計算機上的端口(默認為3128)創建本地代理服務器(127.0.0.1),以與ntlmaps相同的方式工作。 這個新的本地創建的代理服務器不需要任何身份驗證,因此可以與任何支持http代理的應用程序一起使用。 如果需要,它還可以創建本地socks代理。

使用python編寫的ntlmaps的主要優點是cntlm具有非常低的CPU和RAM使用率,通常<2%。

TL / DR:

export GIT_HTTP_PROXY_AUTHMETHOD=basic

要么

git config --global http.proxyauthmethod basic

當git(curl)代理身份驗證不起作用時,我遇到了同樣的問題。 證書是對的。 升級到最新的git-v2.15.0沒有幫助。

問題是由於git-libcurl選擇了錯誤的代理身份驗證方法。

有效的proxy_authmethod選項在git源中定義: https//github.com/git/git/blob/d0e9983980a25e0c398cc03342e5ad22ef85b8a8/http.c#L81

可以通過GIT_HTTP_PROXY_AUTHMETHOD環境變量或http.proxyauthmethod git config選項定義GIT_HTTP_PROXY_AUTHMETHOD方法。 環境變量會覆蓋config選項值。

由於這是我一直在尋找我的搜索工作的問題,我將在這里添加我的答案。

我需要在一個網絡上訪問通過http(s)代理(需要NTLM身份驗證)工作的github.com托管倉庫,並且在正常的互聯網連接上,從我們的Mac OS X開發機器上運行它仍然可以工作。

這是我如何使它工作。 這不適用於每個git托管服務提供商,但我發布以防萬一它可以幫助你解決這個問題。 這也僅適用於Mac OS X,但如果你弄清楚如何為你的系統進行網絡變更運行,其余的應該遵循。

在正常設置ssh訪問后,我不得不使用git clone git@github.com:user/repo.git (http://help.github.com/mac-set-up-git/)。

然后我需要設置一個處理NTLM身份驗證的本地http(s)代理,例如ntlmaps,cntlm或Authoxy。 我已經使用Authoxy進行了測試。 我將把這個配置給你,因為你需要知道你自己的代理細節。

如果你有MacPorts,你還需要開瓶器,這只是sudo port install corkscrew corkscrew。

然后我將以下內容添加到~/.ssh/config

Host github.com.disabled
User git
HostName ssh.github.com
Port 443
ProxyCommand /opt/local/bin/corkscrew localhost 6574 %h %p

其中6574是TCP端口,我設置Authoxy來監聽。

現在我創建了一個腳本,試圖找到http(s)代理服務器,並根據它找到的內容在/usr/local/bin/locationchanger配置ssh設置:

#!/bin/sh

set -o nounset
set -o errexit

sleep 10 # allow for WiFi to actually connect.

# if we can find the proxy server, then use it.
if ! host proxy.internal.network;
then
    echo "Proxy server not found, clearing http(s) proxy";
    sed -i '.backup' -E 's/^Host github.com$/Host github.com.disabled/' "$HOME/.ssh/config"
else
    echo "Proxy server found, setting http(s) proxy";
    sed -i '.backup' -E 's/^Host github.com.disabled$/Host github.com/' "$HOME/.ssh/config"
fi
echo "Done."

別忘了chmod +x /usr/local/bin/locationchanger

現在創建~/Library/LaunchAgents/LocationChanger.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>tech.inhelsinki.nl.locationchanger</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/locationchanger</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>/Library/Preferences/SystemConfiguration</string>
    </array>
</dict>
</plist>

然后launchctl load ~/Library/LaunchAgents/LocationChanger.plist 只要網絡發生變化,此啟動作業就會運行。 如果它可以找到您的內部網絡http(s)代理服務器,它將使ssh使用corkscrew通過Authoxy工作,它將處理通過公司代理工作。 如果它找不到代理服務器,它將禁用特殊的ssh配置,並且你正常工作。

現在我們的團隊不再需要考慮網絡切換了。

我一直在使用ntlmaps並通過Windows / NT代理獲得了良好的結果: http//ntlmaps.sourceforge.net/

git配置是:

git config --global http.proxy http:// localhost:5865

我偶然發現了一個更簡單,更安全的解決方案,它不僅適用於git,也適用於任何基於命令的安裝程序

  • 紅寶石中的Rubygems
  • 節點中的npm

從命令行運行所有流量的一個解決方案代表了真實性。

不要在用戶中公開您的密碼:password @ domain:port format

解:

下載Fiddler ,它有一種內置的方式來為所有請求添加身份驗證標頭。

一旦運行菜單規則 - >自動驗證(勾選)

然后為git

git config --global http.proxy http://localhost:8888
git config --global https.proxy http://localhost:8888

而已!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM