Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make git accept a self signed certificate?

Using Git, is there a way to tell it to accept a self signed certificate?

I am using an https server to host a git server but for now the certificate is self signed.

When I try to create the repo there for the first time:

git push origin master -f 

I get the error:

error: Cannot access URL      https://the server/git.aspx/PocketReferences/, return code 22  fatal: git-http-push failed 
like image 213
Ian Vink Avatar asked Jul 23 '12 23:07

Ian Vink


People also ask

How do I accept a self-signed certificate?

Navigate to the site with the cert you want to trust, and click through the usual warnings for untrusted certificates. In the address bar, right click on the red warning triangle and "Not secure" message and, from the resulting menu, select "Certificate" to show the certificate.

How do I bypass SSL in git?

Prepend GIT_SSL_NO_VERIFY=true before every git command run to skip SSL verification. This is particularly useful if you haven't checked out the repository yet. Run git config http. sslVerify false to disable SSL verification if you're working with a checked out repository already.


1 Answers

To permanently accept a specific certificate

Try http.sslCAPath or http.sslCAInfo. Adam Spiers's answer gives some great examples. This is the most secure solution to the question.

To disable TLS/SSL verification for a single git command

try passing -c to git with the proper config variable, or use Flow's answer:

git -c http.sslVerify=false clone https://example.com/path/to/git 

To disable SSL verification for a specific repository

It is possible to globally deactivate ssl verification. It is highly recommended to NOT do this but it is mentioned for completeness:

git config --global http.sslVerify false # Do NOT do this! 

There are quite a few SSL configuration options in git. From the man page of 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. 

A few other useful SSL configuration options:

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. 
like image 80
Christopher Avatar answered Oct 05 '22 01:10

Christopher