Setting git private repository project on jenkins server

I am trying to set git private repo on jenkins server. I have installed git plugin and also github. when I set repo url in jenkins project ui the error is

Failed to connect to repository : Command "git -c core.askpass=true 
ls-remote -h HEAD" returned 
status code 128:
stderr: Permission denied (publickey).
fatal: The remote end hung up unexpectedl

What I have done up to now:

  1. My server user and jenkin user( both are in same server) are different. Though it seems to me these are not related. jenkins user are given all credintial.

  2. In my server under var/lib/jenkins/.ssh(.ssh is created by me) I added ssh key . Public key is added to github repo.

  3. By swithcting user to jenkins i can clone the project by this ssh. So i think there is not any public key adding problem.

I have googled the problem. there are many solutions. I tried most of them. But still no solution. Probably I am missing something.

My repo url is something like this

  • GitLab SSH keys stopped working
  • Git, can't commit to remote webserver repository
  • gitlab-shell -> git push -u origin master -> fatal: The remote end hung up unexpectedly
  • Can't clone remote Git mirror over HTTP, but can over SSH
  • port automatically changed to proxy port when applying a http proxy for ssh access to github
  • Gitlab can't clone repository even though ssh works
  • How to use old SSH key from Windows to Ubuntu?
  • Git post-update hook cannot pull
  • 2 Solutions collect form web for “Setting git private repository project on jenkins server”

    If your HOME set in /var/lib/jenkins/ then i hope all the step you have been done successfully 🙂

    Then one thing may be happen for your case. Like when you switch the user by using:

    su jenkins 

    This command means that you switch the user but the home directory will be same as a root’s home!

    So you need to switch user by confirming the specific user home also switched. TO doing so, you need to follow:

    su -s /bin/bash jenkins

    Then you need to generate either the ssh public key once again or just update the known host. This will work.

    Related Link

    It depends on what HOME is set to when Jenkins is running: git will look for the ssh (public and private) keys under $HOME/.ssh.

    Simply add a build step with an echo $HOME, and make sure your .ssh is in that folder.

    Git Baby is a git and github fan, let's start git clone.