使用Git,是否有一种方法告诉它接受自签名证书?

我使用https服务器托管git服务器,但目前证书是自签名的。

当我第一次尝试在那里创建回购时:

git push origin master -f

我得到了错误:

error: Cannot access URL     
https://the server/git.aspx/PocketReferences/, return code 22

fatal: git-http-push failed

当前回答

在使用sslKey或sslCert使用一行程序时要小心,如Josh Peak的回答所示:

git clone -c http.sslCAPath="/path/to/selfCA" \
  -c http.sslCAInfo="/path/to/selfCA/self-signed-certificate.crt" \
  -c http.sslVerify=1 \
  -c http.sslCert="/path/to/privatekey/myprivatecert.pem" \
  -c http.sslCertPasswordProtected=0 \
https://mygit.server.com/projects/myproject.git myproject

只有Git 2.14.x/2.15(2015年Q3)能够正确地解释~username/mykey这样的路径(同时它仍然可以解释/path/to/privatekey这样的绝对路径)。

参见Junio C Hamano (gitster)提交的8d15496(2017年7月20日)。 资助人:查尔斯·贝利(hashpling)。 (由Junio C Hamano合并- gitster -在commit 17b1e1d, 2017年8月11日)

http.c: http.sslcert and http.sslkey are both pathnames Back when the modern http_options() codepath was created to parse various http.* options at 29508e1 ("Isolate shared HTTP request functionality", 2005-11-18, Git 0.99.9k), and then later was corrected for interation between the multiple configuration files in 7059cd9 ("http_init(): Fix config file parsing", 2009-03-09, Git 1.6.3-rc0), we parsed configuration variables like http.sslkey, http.sslcert as plain vanilla strings, because git_config_pathname() that understands "~[username]/" prefix did not exist. Later, we converted some of them (namely, http.sslCAPath and http.sslCAInfo) to use the function, and added variables like http.cookeyFile http.pinnedpubkey to use the function from the beginning. Because of that, these variables all understand "~[username]/" prefix. Make the remaining two variables, http.sslcert and http.sslkey, also aware of the convention, as they are both clearly pathnames to files.

其他回答

我是这样做的:

git init
git config --global http.sslVerify false
git clone https://myurl/myrepo.git

在Windows上,这对我来说很管用:

将自签名证书的内容添加到ca-bundle文件的末尾。包括-----BEGIN CERTIFICATE-----和-----END CERTIFICATE-----行

ca-bundle文件的位置通常是C:\Program Files\Git\mingw64\ssl\certs

然后,将ca-bundle文件的路径添加到全局git配置中。下面的命令可以做到这一点:git config——global http。sslCAInfo "C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt"

注意:路径依赖于ca-bundle文件的本地路径!

在Windows上使用64位版本的Git,只需将自签名CA证书添加到这些文件中:

C:\Program Files\Git\mingw64\ssl\certs\ ca-bundle.crt C:\Program Files\Git\mingw64\ssl\certs\ ca-bundle.trust.crt

如果它只是一个服务器自签名证书,请将其添加到

C:\Program Files\Git\mingw64\ssl\cert.pem

它为我工作,只需运行以下命令

git config --global http.sslVerify false

它将打开一个git凭据窗口,提供您的凭据。第一次只有它问

设置http不是一个好的做法。sslVerify假。 相反,我们可以使用SSL证书。

因此,构建代理将使用https与SSL证书和PAT进行身份验证。

复制cer文件的内容,包括- begin -和-end——。

Git bash build agent => Git配置-global http。sslcainfo " C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt " 转到该文件并添加.cer内容。

因此,构建代理可以访问SSL证书