Sometimes could happen that jenkins cannot work good with github repos in our project dependencies.
Errors could be something like:
firstname.lastname@example.org:zendframework/zend-uri.git Cloning into '/var/www/vendor/zendframework/zend-uri'... Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Cloning into 'zend-uri'... Permission denied (publickey). fatal: Could not read from remote repository.
For avoid these type of errors, you can add a public ssh key to your jenkins user:
1. First of all, you have to connect to the host and change the user to “jenkins”:
$ su jenkins
2. After that, try to see if we have already the ssh public key:
$ ssh -T email@example.com Permission denied (publickey).
3. We don’t have it yet, so we create with (Hit enter at every request):
$ ssh-keygen -t rsa -b 4096 -C "firstname.lastname@example.org" Generating public/private rsa key pair. Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa. Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub.
4. Now we start the ssh agent:
$ eval "$(ssh-agent -s)" Agent pid 1011
5. And add our new public key in the system:
$ ssh-add ~/.ssh/id_rsa Identity added: /var/lib/jenkins/.ssh/id_rsa (/var/lib/jenkins/.ssh/id_rsa)
6. Ok, now we need to add this new public key to our account, follow this instructions.
7. Now we can try again to connect to github:
$ ssh -T email@example.com Warning: Permanently added the RSA host key for IP address '188.8.131.52' to the list of known hosts. Hi github_user! You've successfully authenticated, but GitHub does not provide shell access.