Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I get the following error when accessing Github over HTTPS:

error: server certificate verification failed. 
CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

This is because I don't have any certificates in /etc/ssl/certs/. I know how to fix this problem. I can install the package ca-certificates from Debian repository. The problem is, however, that this will install all certificates (thousands) which I don't necessarily want to accept/trust.

How can I install certificate for Github only?

a Subproblem/Subquestion

On another machine, where the package ca-certificates is already installed and git works, I have noticed that some certificates in /etc/ssl/certs/ are one-certificate-per-file and other are many-certificates-in-one-file. The particular file containing Github certificate, /etc/ssl/certs/ca-certificates.crt contains over 150 other certificates:

$ grep 'BEGIN CERTIFICATE' /etc/ssl/certs/ca-certificates.crt | wc -l
159

How can I find which one out of these 159 certificate is the one I need? (other than brute force - slicing the file in halves and checking both halves, repeating while n > 1).

share|improve this question
    
What are you trying to accomplish? Contacting GitHub programmatically? –  Nate W. Jan 25 at 7:12
    
Have you tried downloading the source package and then extracting only the cert you want? –  jayhendren May 23 at 21:16
    
What are you using to access github? some command-line tool? a browser? –  lk- May 25 at 21:30
    
Thanks a lot for accepting! –  bersch May 28 at 15:25
add comment

2 Answers 2

up vote 3 down vote accepted
+50

In order to access your Github you need to do it via ssh. So you need to add your ssh public key to github. After that you are able to access github via ssh i.e.:

git init git@github.com:yourname/yourrepo.git

See also: Github: generating ssh keys, WikiHow

[Edit #1]

without certificate checks:

GIT_SSL_NO_VERIFY=true git clone https://github.com/p/repo.git

or authenticated

GIT_SSL_NO_VERIFY=true git clone https://user@pass:github.com/p/repo.git

For me it is still not clear what are you asking for, because you know that installing ca-certificates will fix the problem.

[Edit #2]

Ok, the other question was

how to have only the certificate which is needed to access github.com via https

  1. Open your browser and navigate to https://github.com/. Klick on the green name on the left from https:// and klick on Certificates. On the Details tab, you'll see the certificate chain, which is:

    DigiCert ...
      DigiCert ...
       github.com ...
    
  2. Export each of the DigiCert certicates to a file.

  3. copy the files to /etc/ssl/certs/
  4. run c_rehash which cat all certificates to ca-certificates.crt
  5. you are done.

As I said, I am not a friend of such actions because github can change the CA's anytime, so it will always result in additional work.

share|improve this answer
    
Thank you for the suggestion. But I would like to access github via https. –  Martin Vegter May 23 at 19:40
add comment

As was suggested previously, you could use SSH keys, instead of relying on HTTPS to avoid this problem, and arguably, enjoy better security.

Having said that, I think what you are looking for is how to install root/CA certificates in /etc/ssl/certs. In a nutshell, it isn't sufficient to just dump the PEM-encoded file into /etc/ssl/certs - you also have to calculate the hash of said certificate, and create a symlink in /etc/ssl/certs to that cert file. The name of the symlink, has to be the hash suffixed by .0, or if there is a hash collision, .1, and so on.

Here's a detailed writeup, as well as a sample script you can use to automate the process: http://wiki.openwrt.org/doc/howto/wget-ssl-certs#adding.root.certificates

Hope this is what you were looking for, but like I said earlier, SSH keys are probably the "better" solution. :)

share|improve this answer
    
c_rehash is doing what you explained. See c_rehash man page. BTW: there is no need to calculate the hashes. Catting the certs to ca-certificates.crt is sufficient, since git reads only this file. Furthermore the link explained how to manually get the certificates with openssl. This is very doubtful and provokes a man in the middle attack. I wouldn't recommend it. –  bersch May 26 at 14:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.