简体   繁体   中英

Jenkins is not able to connect to GIT with SSH, but shell works

I have 2 Virtual Machines (both Ubuntu 12), SRV-ATLASSIAN (where Stash is installed) and SRV-CI (where Jenkins is installed).

I want to use the Git Plugin for Jenkins, so i installed it, created a SSH key on SRV-ATLASSIAN and copied the private key (id_rsa) to /var/lib/jenkins/.ssh

I ssh-add the key

When i type in

sudo su jenkins
cd /var/lib/jenkins/.ssh
git clone ssh://git@10.10.10.21:7999/test/test.git

on the shell, it does work perfectly.

When i enter this URI into the GIT Plugin of jenkins, i get the following error message:

Using strategy: Default
Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway
hudson.plugins.git.GitException: Command "git fetch -t origin     +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Permission denied (publickey).
fatal: The remote end hung up unexpectedly

I've googled of course about this problem, but i don't understand what exactly to do to make it work. It is strange that i can clone from the shell AS THE USER "JENKINS" but Jenkins itself can't..

You need to give the Jenkins user access to your Stash repos. Create a user in Stash and add the SSH public key for the Jenkins user to the Stash user. Then set up permissions for your Stash projects or individual repos so that the Jenkins user can access the repos you need. See the Stash docs for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM