Permission denied (public key) during fetch from GitHub with Jenkins user on Ubuntu

前端 未结 8 806
盖世英雄少女心
盖世英雄少女心 2021-02-02 07:56

Here is my setup:

  1. Jenkins is running on my linux machine as \'jenkins\' user.
  2. I have generated a ssh key-pair as described in Linux - Setup Git, for the \
相关标签:
8条回答
  • 2021-02-02 08:19

    I would add that if you created the keys by hand, they might still be owned by you and not readable by jenkins, try:

    sudo chown jenkins -R /var/lib/jenkins/.ssh/*
    
    0 讨论(0)
  • 2021-02-02 08:21

    I got around this problem by simply leaving the passphrase empty when creating the keys.

    0 讨论(0)
  • 2021-02-02 08:21

    keys need to generated from jenkins user.

    sudo su jenkins
    ssh-keygen
    

    once the key is generated, it should be added as ssh key in bitbucket or github.

    0 讨论(0)
  • 2021-02-02 08:22

    For Mac users, the issue can be solved by removing the existing keys and creating new Private and Public Keys by following these steps:

    1.Remove all Public and Private keys located at /Users/Username/.ssh

    2.Remove all the credentials saved under the Credentials tab in Jenkins.

    3.Remove the existing Public SSH keys defined in the Github Repository Settings.

    4.Create new SSH keys (private and public: id_rsa and id_rsa.pub) by following the steps from https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html#CreatingSSHkeys-CreatinganSSHkeyonLinux&MacOSX

    5.Set the newly created public SSH key (id_rsa.pub) in Github or an equivalent Repository Settings.

    6.In Jenkins,create new credentials by adding the private SSH key(id_rsa) for your Github username.

    7.The Error should be removed now.

    0 讨论(0)
  • 2021-02-02 08:33

    To summarise what must be done on the Jenkins server:

    # 1. Create the folder containing the SSH keys if necessary
    if [ ! -e ~jenkins/.ssh ]; then mkdir ~jenkins/.ssh; fi
    cd ~jenkins/.ssh/
    
    # 2. Create the SSH pair of keys
    # The comment will help to identify the SSH key on target systems
    ssh-keygen -C "jenkins" -f ~jenkins/.ssh/id_rsa -P ""
    
    # 3. Assign the proper access rights
    chown -R jenkins ~jenkins/.ssh/
    chmod 700 ~jenkins/.ssh
    chmod 600 ~jenkins/.ssh/*
    

    Remember:

    • Please keep the default "id_rsa" name when generating the keys, as other such as "id_rsa_jenkins" won't work, even if correctly set up.
    • Do not use a passphrase for your key
    • Check that the public key (id_rsa.pub) has been uploaded on the git server (GitHub, Bitbucket, etc). Once done, test your SSH key by running: ssh -vvv git@github.com (change address according to your git server)
    0 讨论(0)
  • 2021-02-02 08:34

    Since nobody wrote the answer from the comments for several months, I will quickly do so.

    There are 2 possible problems/solutions:

    1. id_rsa created with wrong user

      Create id_rsa as the jenkins user (see hudson cannot fetch from git repository)

    2. Leave passphrase empty

    0 讨论(0)
提交回复
热议问题