Managing SSH keys within Jenkins for Git
It looks like the github.com
host which jenkins tries to connect to is not listed under the Jenkins user's $HOME/.ssh/known_hosts
. Jenkins runs on most distros as the user jenkins
and hence has its own .ssh
directory to store the list of public keys and known_hosts
.
The easiest solution I can think of to fix this problem is:
# Login as the jenkins user and specify shell explicity,# since the default shell is /bin/false for most# jenkins installations.sudo su jenkins -s /bin/bashcd SOME_TMP_DIR# git clone YOUR_GITHUB_URL# Allow adding the SSH host key to your known_hosts# Exit from suexit
Have you tried logging in as the jenkins user?
Try this:
sudo -i -u jenkins #For RedHat you might have to do 'su' instead.git clone git@github.com:your/repo.git
Often times you see failure if the host has not been added or authorized (hence I always manually login as hudson/jenkins for the first connection to github/bitbucket) but that link you included supposedly fixes that.
If the above doesn't work try recopying the key. Make sure its the pub key (ie id_rsa.pub). Maybe you missed some characters?
According to this article, you may try following command:
ssh-add -l
If your key isn't in the list, then
ssh-add /var/lib/jenkins/.ssh/id_rsa_project