Ian*_*ink 602 git version-control https self-signed
使用Git,有没有办法告诉它接受自签名证书?
我使用https服务器来托管git服务器但是现在证书是自签名的.
当我第一次尝试在那里创建回购时:
git push origin master -f
Run Code Online (Sandbox Code Playgroud)
我收到错误:
error: Cannot access URL
https://the server/git.aspx/PocketReferences/, return code 22
fatal: git-http-push failed
Run Code Online (Sandbox Code Playgroud)
Chr*_*her 1087
试试http.sslCAPath或http.sslCAInfo.Adam Spiers的回答给出了一些很好的例子.这是该问题最安全的解决方案.
尝试通过-c以git与适当的配置变量,或使用流量的回答:
git -c http.sslVerify=false clone https://example.com/path/to/git
Run Code Online (Sandbox Code Playgroud)
如果存储库完全在您的控制之下,您可以尝试:
git config http.sslVerify false
Run Code Online (Sandbox Code Playgroud)
全局禁用TLS(/ SSL)证书验证是一种非常不安全的做法.不要这样做.不要使用--global修饰符发出上述命令.
有很多SSL配置选项git.从手册页git config:
http.sslVerify
Whether to verify the SSL certificate when fetching or pushing over HTTPS.
Can be overridden by the GIT_SSL_NO_VERIFY environment variable.
http.sslCAInfo
File containing the certificates to verify the peer with when fetching or pushing
over HTTPS. Can be overridden by the GIT_SSL_CAINFO environment variable.
http.sslCAPath
Path containing files with the CA certificates to verify the peer with when
fetching or pushing over HTTPS.
Can be overridden by the GIT_SSL_CAPATH environment variable.
Run Code Online (Sandbox Code Playgroud)
一些其他有用的SSL配置选项:
http.sslCert
File containing the SSL certificate when fetching or pushing over HTTPS.
Can be overridden by the GIT_SSL_CERT environment variable.
http.sslKey
File containing the SSL private key when fetching or pushing over HTTPS.
Can be overridden by the GIT_SSL_KEY environment variable.
http.sslCertPasswordProtected
Enable git's password prompt for the SSL certificate. Otherwise OpenSSL will
prompt the user, possibly many times, if the certificate or private key is encrypted.
Can be overridden by the GIT_SSL_CERT_PASSWORD_PROTECTED environment variable.
Run Code Online (Sandbox Code Playgroud)
Flo*_*low 159
您可以设置GIT_SSL_NO_VERIFY为true:
GIT_SSL_NO_VERIFY=true git clone https://example.com/path/to/git
Run Code Online (Sandbox Code Playgroud)
或者配置Git不要在命令行上验证连接:
git -c http.sslVerify=false clone https://example.com/path/to/git
Run Code Online (Sandbox Code Playgroud)
请注意,如果您未验证SSL/TLS证书,则您很容易受到MitM攻击.
Ada*_*ers 131
我不是[EDIT:现有答案的原始版本]的忠实粉丝,因为禁用安全检查应该是最后的手段,而不是第一个提供的解决方案.即使您在第一次收到时无法信任自签名证书而没有其他一些额外的验证方法,但使用证书进行后续git操作至少会使您的生活更加困难,这种攻击只有在您下载证书后才会发生.换句话说,如果您下载的证书是真实的,那么从那时起您就会很好.相反,如果您只是禁用验证,那么您在任何时候都可以接受任何类型的中间人攻击.
举一个具体的例子:着名的repo.or.cz存储库提供了一个自签名证书.我可以下载该文件,将其放在某处/etc/ssl/certs,然后执行:
# Initial clone
GIT_SSL_CAINFO=/etc/ssl/certs/rorcz_root_cert.pem \
git clone https://repo.or.cz/org-mode.git
# Ensure all future interactions with origin remote also work
cd org-mode
git config http.sslCAInfo /etc/ssl/certs/rorcz_root_cert.pem
Run Code Online (Sandbox Code Playgroud)
请注意,git config在此处使用local (即不使用--global)意味着此自签名证书仅对此特定存储库可信,这很好.它也比使用更好,GIT_SSL_CAPATH因为它消除了git通过可能被泄露的不同证书颁发机构进行验证的风险.
Jos*_*eak 30
对于我自己和同事们来说,这里是我们如何设法让自签名证书在没有禁用的情况下工作http.sslverify.编辑你http.sslCAPath的使用http.sslCAInfo添加这些:
# Specify the scheme and host as a 'context' that only these settings apply
# Must use Git v1.8.5+ for these contexts to work
[credential "https://your.domain.com"]
username = user.name
# Uncomment the credential helper that applies to your platform
# Windows
# helper = manager
# OSX
# helper = osxkeychain
# Linux (in-memory credential helper)
# helper = cache
# Linux (permanent storage credential helper)
# https://askubuntu.com/a/776335/491772
# Specify the scheme and host as a 'context' that only these settings apply
# Must use Git v1.8.5+ for these contexts to work
[http "https://your.domain.com"]
##################################
# Self Signed Server Certificate #
##################################
# MUST be PEM format
# Some situations require both the CAPath AND CAInfo
sslCAInfo = /path/to/selfCA/self-signed-certificate.crt
sslCAPath = /path/to/selfCA/
sslVerify = true
###########################################
# Private Key and Certificate information #
###########################################
# Must be PEM format and include BEGIN CERTIFICATE / END CERTIFICATE,
# not just the BEGIN PRIVATE KEY / END PRIVATE KEY for Git to recognise it.
sslCert = /path/to/privatekey/myprivatecert.pem
# Even if your PEM file is password protected, set this to false.
# Setting this to true always asks for a password even if you don't have one.
# When you do have a password, even with this set to false it will prompt anyhow.
sslCertPasswordProtected = 0
Run Code Online (Sandbox Code Playgroud)
参考文献:
http.sslCert-ing 时指定config如果您需要在每个repo的基础上应用它,文档会告诉您只需http.sslCertPasswordProtected在repo目录中运行.那么当你没有在当地克隆回购时这没用,现在是吗?
您可以http.<url>.*通过如上设置全局配置来执行hokey-pokey,然后在克隆后将这些设置复制到本地repo配置...
或者你可以做的是指定.gitconfig一旦克隆就应用于目标仓库的配置命令.
# Declare variables to make clone command less verbose
OUR_CA_PATH=/path/to/selfCA/
OUR_CA_FILE=$OUR_CA_PATH/self-signed-certificate.crt
MY_PEM_FILE=/path/to/privatekey/myprivatecert.pem
SELF_SIGN_CONFIG="-c http.sslCAPath=$OUR_CA_PATH -c http.sslCAInfo=$OUR_CA_FILE -c http.sslVerify=1 -c http.sslCert=$MY_PEM_FILE -c http.sslCertPasswordProtected=0"
# With this environment variable defined it makes subsequent clones easier if you need to pull down multiple repos.
git clone $SELF_SIGN_CONFIG https://mygit.server.com/projects/myproject.git myproject/
Run Code Online (Sandbox Code Playgroud)
编辑:请参阅VonC的回答,指出关于特定git版本从2.14.x/2.15到这一个班轮的绝对路径和相对路径的警告
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/
Run Code Online (Sandbox Code Playgroud)
sslVerify如果您在CentOS上尝试这个并且您的.gitconfig文件正在给您
unable to load client key: "-8178 (SEC_ERROR_BAD_KEY)"
Run Code Online (Sandbox Code Playgroud)
然后,您将需要此StackOverflow答案,了解如何git config --global -e使用NSS而不是Open SSL.
你想要从源代码重建git clone:
git clone http://github.com/curl/curl.git curl/
cd curl/
# Need these for ./buildconf
yum install autoconf automake libtool m4 nroff perl -y
#Need these for ./configure
yum install openssl-devel openldap-devel libssh2-devel -y
./buildconf
su # Switch to super user to install into /usr/bin/curl
./configure --with-openssl --with-ldap --with-libssh2 --prefix=/usr/
make
make install
Run Code Online (Sandbox Code Playgroud)
重启计算机,因为libcurl仍然作为共享库在内存中
相关:如何将自定义CA根证书添加到Windows中的Python使用的CA Store中?
Cra*_*aig 14
我一直遇到这个问题,所以编写了一个脚本从服务器下载自签名证书并将其安装到〜/ .gitcerts,然后更新git-config指向这些证书.它存储在全局配置中,因此您只需要为每个远程运行一次.
https://github.com/iwonbigbro/tools/blob/master/bin/git-remote-install-cert.sh
Sau*_*rma 12
禁用特定存储库的 SSL 验证 如果存储库完全在您的控制之下,您可以尝试:
git config --global http.sslVerify false
Run Code Online (Sandbox Code Playgroud)
Pal*_*Roy 12
将 http.sslVerify 设置为 false 不是一个好习惯。相反,我们可以使用 SSL 证书。
因此,构建代理将使用带有 SSL 证书和 PAT 的 https 进行身份验证。

复制cer文件的内容,包括-begin-和-end--。
git bash on build agent => git config –global http.sslcainfo “C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt” 转到此文件并附加 .cer 内容。
因此,构建代理可以访问 SSL 证书
这个答案摘自Michael Kauffman撰写的这篇文章.
使用Git for Windows和公司SSL证书
问题:
如果您拥有公司SSL证书并希望从控制台或VSCode克隆您的存储库,则会出现以下错误:
致命:无法访问' https:// myserver/tfs/DefaultCollection/_git/Proj / ':SSL证书问题:无法获取本地颁发者证书
方案:
将根自签名证书导出到文件.您可以在浏览器中执行此操作.
在git文件夹中找到"ca-bundle.crt"文件(当前版本C:\ Program Files\Git\usr\ssl\certs,但过去已更改).将文件复制到您的用户配置文件.使用VSCode等文本编辑器打开它,并将导出的证书的内容添加到文件的末尾.
现在我们必须配置git来使用新文件:
git config --global http.sslCAInfo C:/Users/<yourname>/ca-bundle.crt
这会将以下条目添加到用户配置文件根目录中的.gitconfig文件中.
[http]
sslCAInfo = C:/Users/<yourname>/ca-bundle.crt
在 Windows 上使用 64 位版本的 Git,只需将自签名 CA 证书添加到这些文件中:
如果它只是一个服务器自签名证书,请将其添加到
小智 5
检查您的防病毒和防火墙设置。
一天天过去了,git 不再工作了。通过上面的描述,我发现卡巴斯基在中间放了一个自签名的反病毒个人根证书。我没有按照上面的说明让 Git 接受该证书。我放弃了。对我有用的是禁用扫描加密连接的功能。
此后,git 再次在启用 sslVerify 的情况下工作。
笔记。这对我来说仍然不满意,因为我希望激活我的防病毒软件的该功能。在高级设置中,卡巴斯基会显示无法使用该功能的网站列表。Github 没有被列为其中之一。我去卡巴斯基论坛看看。似乎有一些主题,例如 https://forum.kaspersky.com/index.php?/topic/395220-kis-interfering-with-git/&tab=comments#comment-2801211
在 Windows 上,这对我有用:
将自签名证书的内容添加到ca-bundle文件的末尾。包括-----BEGIN CERTIFICATE-----和-----END CERTIFICATE-----行
ca-bundle文件的位置通常是C:\Program Files\Git\mingw64\ssl\certs
然后,将ca-bundle文件的路径添加到全局 git config 中。下面的命令可以解决这个问题:git config --global http.sslCAInfo "C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt"
备注:路径取决于 ca-bundle 文件的本地路径!
| 归档时间: |
|
| 查看次数: |
681654 次 |
| 最近记录: |