I'm having a frustrating time getting this set up. Currently my Bitbucket account is having a problem connecting over HTTPS and so I'm trying to connect to my repo using SSH but have encountered problems.
This is my first time using Jenkins so bear with me. I installed Jenkins using homebrew which was very simple.
~/.ssh folder[email protected]:myrepo.git URL.My efforts were rewarded with this error:
Failed to connect to repository : Command "git ls-remote -h [email protected]:myrepo.git HEAD" returned status code 128: stdout: stderr: Permission denied (publickey). fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
I've heard it said that Jenkins creates a new user on your machine and that the reason the SSH key might not work is because the jenkins user does not have access to it. I have not found any evidence of it creating a user and have even heard that it does not create a user, maybe this was old behaviour.
I've tried switching to this Jenkins users as suggested here but to no avail.
Any help would be appreciated.
Edit: One additional thing I've heard (somewhere) is that it might work better if your SSH keys were created without a passphrase. Sounds like it would be less secure in that case so I'm not sure if I should try that.
Okay I just found out what was going on.
Even though I added my SSH key to Jenkins and it was accessible via the Credentials dropdown in the Source Code Management section of my project the ssh-agent on my machine (which Jenkins uses) didn't know about my keys and I needed to add them.
Solution:
On the machine where Jenkins is installed:
- Open up a terminal
- Enter:
ssh-add -l- If you don't see your keys listed (mine said "The agent has no identities.") then you'll need to add them. Enter:
ssh-add <path-to-key>(the default path is usually something like~/.ssh/id_rsa)- If you have a passphrase for your key you'll need to enter it here.
- Now go back to your Jenkins project, add your repo URL, then select your credentials and it should work
Hope that helps someone avoid wasting their time like I did.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With