jenkins/hudson can't connect to github repo

33,374

Solution 1

The error seems to be: host key verification failed.

You should log into your Jenkins host as the Jenkins user and run:

ssh [email protected]

Then answer yes to the prompt about the host key. This only needs to be done once.

Alternatively you could add "StrictHostKeyChecking no" to ~jenkins/.ssh/config.

Solution 2

1) Switch User into your jenkins account

su jenkins

2) Create the key without a passphrase

3) ssh [email protected]

That worked perfectly for me.

You may need to create a password for the jenkins account, if so use sudo passwd jenkins

Solution 3

He following helped me:

Login under Jenkins

sudo su jenkins

Copy your github key to Jenkins .ssh folder

cp ~/.ssh/id_rsa_github* /var/lib/jenkins/.ssh/

Raname the keys

mv id_rsa_github id_rsa
mv id_rsa_github.pub id_rsa.pub

Solution 4

I'm using a single jenkins machine to check out multiple github repositories and had similar problems when setting it up. What I ended up doing was configuring an SSH config file for jenkins so that SSH would automatically know which id file to associate with each repository.

/var/lib/jenkins/.ssh/config:

Host github-ABC
  HostName github.com
  User git
  IdentityFile /var/lib/jenkins/.ssh/id_rsa_ABC

In the Jenkins project config under source code management, I used this as the repository name:

git@github-ABC:user/repo.git

Finally, I use the SSH public key as a deploy key in the github repository.

Solution 5

If you log in as jenkins you can do

ssh -i ~/.ssh/id_rsa [email protected]

where ~/.ssh/id_rsa is the path/to/your/ssh/key and it will prompt for the password and add to the known_hosts file

Share:
33,374
Chris Mccabe
Author by

Chris Mccabe

Developer of social media integration technology utilising rfid and nfc technologies for events and loyalty schemes- main is lamphp and do qa as well

Updated on April 29, 2020

Comments

  • Chris Mccabe
    Chris Mccabe about 4 years

    I am on Ec2 with the base amazon ami linux- I have installed jenkins but when I go to pull the repo from github I am given the following error:

    Building in workspace /var/lib/jenkins/workspace/build social
    Checkout:build social / /var/lib/jenkins/workspace/build social - hudson.remoting.LocalChannel@5c7b21b
    Using strategy: Default
    Cloning the remote Git repository
    Cloning repository origin
    ERROR: Error cloning remote repo 'origin' : Could not clone [email protected]:adulion/.git
    hudson.plugins.git.GitException: Could not clone [email protected]:adulion/.git
        at hudson.plugins.git.GitAPI.clone(GitAPI.java:245)
        at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1117)
        at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1059)
        at hudson.FilePath.act(FilePath.java:832)
        at hudson.FilePath.act(FilePath.java:814)
        at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1059)
        at hudson.model.AbstractProject.checkout(AbstractProject.java:1218)
        at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:581)
        at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:470)
        at hudson.model.Run.run(Run.java:1421)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
        at hudson.model.ResourceController.execute(ResourceController.java:88)
        at hudson.model.Executor.run(Executor.java:238)
    Caused by: hudson.plugins.git.GitException: Command "git clone --progress -o origin [email protected]:adulion/.git /var/lib/jenkins/workspace/build social" returned status code 128:
    stdout: Cloning into /var/lib/jenkins/workspace/build social...
    
    stderr: Host key verification failed.
    fatal: The remote end hung up unexpectedly
    

    I have generated a key for the current user who installed jenkins and have managed to clone the repo using the git command line but jenkins can not.

    I have copied the ~/.ssh files into /var/lib/jenkins/.ssh

    I have added github to the known hosts and I have run out of solutions to try. Anyone know where I am going wrong? Is there a way to get jenkins to show the public key it's using and I can debug if it's using the correct one?

    I removed the name of the repo because its a private repo

  • Chris Mccabe
    Chris Mccabe about 12 years
    do i need to load the config file somewhere?
  • mpdaugherty
    mpdaugherty about 12 years
    No, SSH should automatically look at ~/.ssh/config when connecting. Documentation
  • Richard Barnett
    Richard Barnett almost 12 years
    ssh [email protected] doesn't prompt about the host key, instead echoing PTY allocation request failed on channel 0 / Hi ${NAME}! You've successfully authenticated, but GitHub does not provide shell access.. StrictHostKeyChecking no, however, worked like a charm.
  • Sean Dixon
    Sean Dixon almost 11 years
    I think adding github to the known_hosts will also work? ssh-keyscan -H github.com >> ~/.ssh/known_hosts
  • GoYun.Info
    GoYun.Info over 10 years
    If your jenkins is headless, another convenient way is to ssh [email protected] from another user, and then copy the .ssh/know_hosts file to for example ~jenkins/.ssh/. Also make sure that you chown jenkins:jenkins to all the files in ~jenkins/.ssh
  • Lyserty
    Lyserty over 5 years
    I have this issue trying connection to private GitLab repo. When I test connection from hos (Jenkins ver. 2.146 on docker) ssh -T [email protected] it successful but when Jenkins run build it still fail to fetch it. Suggestions above doesn't work.