Jenkins : stderr: Permission denied (publickey). fatal: The remote end hung up unexpectedly
21,556
Solution 1
- Log into your server with the user you installed Jenkins and put your ssh keys under home directory (cd ~). You should have .ssh folder with your public and private keys.
- Go to your Jenkins server : http://JenkinsMaster:Port/credentials and press "Add credentials"
- Select SSH Username with private key
- Scope is Global
- Username as the user that generated the SSH key
- Private key from the Jenkins master ~/.ssh
- Add description such as "service for GIT"
- In your job after selecting GIT as your SCM select those credentials (the field under the repository called credentials)
Good luck!
Solution 2
When you add new credentials to use jenkins, the private key (.ssh/id_rsa ) should be generate by the user jenkins.
- sudo -i -u jenkins
- mkdir ~/.ssh
- cd ~/.ssh
- ssh-keygen -t rsa -C "jenkins@git"
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_rsa
- cat id_rsa.pub Copy the output and add it to your Git repo. done
Author by
Shwet
Updated on July 09, 2022Comments
-
Shwet almost 2 years
I am hosting Jenkins on a virtual machine(redhat). I am able to setup jenkins system on it and able to access jenkins. But on manage jenkins page while creating any build job, when I giv my git repository link, I am getting this error -
Failed to connect to repository : Command "git ls-remote -h ssh://git.aaa.aaaa.corp:XXXXX/BSA/myProject.git HEAD" returned status code 128: stdout: stderr: Permission denied (publickey). fatal: The remote end hung up unexpectedly
I tried to follow many solutions related to SSH keys but of no help.
PLs help.