adi369
adi369

Reputation: 59

Not able to access git repo from jenkins

I have configured Jenkins on a Linux machine and my git repo is on an another Linux server. But when I try to give the URL of the repo to Jenkins I get the following error.

Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h ssh://user@ip/~/export1 HEAD" returned status code 128:
stdout: 
stderr: Permission denied, please try again. 
Permission denied, please try again. 
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). 
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

What could be the cause for this?

I have seen that both the systems' rsa key is present in each other's .ssh/known_hosts folder.
I am able to pull or clone code from the repo to a folder in Jenkins system as well. So why is Jenkins not able to take it?
I have also tried the URL user@ip:/fullpath/to/repo

Upvotes: 3

Views: 3268

Answers (3)

adi369
adi369

Reputation: 59

The main problem was the security of the systems. I hadnt checked the authentication mechanisms on my server. The password authentication to the git server was causing the problem because the jenkins machine tries to directly fire a ls-remote to the path. When you do the same thing on the terminal you will be prompted for a password and then itl accept. When I set the password authentication and UsePAM to no and enabled the RSA authentication, pubkey authentication and authorised key setting to yes in the sshd_config file, and restarted, it was able to access the repo and I dint get this error.

Upvotes: 0

gareth_bowles
gareth_bowles

Reputation: 21160

Further to @VonC's reply, you can also use the Credentials plugin to define a set of credentials on your Jenkins master that your Jenkins job uses to access your Git repo. This allows you to run Jenkins itself as a different user from there one that has access to the Git repo.

Upvotes: 0

VonC
VonC

Reputation: 1329682

You need to make sure Jenkins is running as the right user (the one who has the keys in ~/.ssh/id_rsa(.pub)

That user might not be the same as the one used in the ssh url: user@ip means you are connecting to ip using an account which has your public key in ~user/.ssh/authorized_key.

So the Jenkins process must be run by an account which has the private and public key, whose public key is in ~user/.ssh/authorized_key on the git server side.
And that account should have done (only once) an ssh-keyscan -H ip >> ~account/.ssh/known_hosts before any ssh attempt, in order to record the git server ip as a known host.

Does it being a bare repo make any difference or change in the URL?

No. The .git at the end of the bare repo folder is optional when used as an url.

Upvotes: 2

Related Questions