GitHub Error Message - Permission denied (publickey)

后端 未结 30 2094
长发绾君心
长发绾君心 2020-11-22 04:23

Anybody seen this error and know what to do?

I\'m using the terminal, I\'m in the root, the GitHub repository exists and I don\'t know what to do now.



        
相关标签:
30条回答
  • 2020-11-22 05:22

    First, we need to check for existing ssh keys on your computer. Open up Terminal and run:

    ls -al ~/.ssh
    
    #or
    
    cd ~/.ssh
    ls
    

    and that will lists the files in your .ssh directory

    And finally depending on what you see (in my case was):

     github_rsa  github_rsa.pub known_hosts
    

    Just try setting up your RSA and hopefully that will solve your "git push origin" issues

    $ ssh-keygen -lf ~/.ssh/github_rsa.pub

    NOTE: RSA certificates are keys-paired so you will have a private and a public certificate, private will not be accessible for you since it belongs to github (in this case) but the public is the one you might be missing when this error happens (at least that was my case, my github account or repo got messed up somehow and i had to "link" the public key, previously generated)

    0 讨论(0)
  • 2020-11-22 05:22

    I was having a similar problem to @Batman. However, because I was running this under /usr/local/src/projectname, running without sudo was not an option.

    Just add the -E flag to preseve the environment (your ~/.ssh/ path).

    $ sudo -E git clone git@your_repo

    From man sudo:

    -E, --preserve-env Indicates to the security policy that the user wishes to pre‐ serve their existing environment variables. The security policy may return an error if the user does not have permis‐ sion to preserve the environment.

    0 讨论(0)
  • 2020-11-22 05:23

    Another solution :

    create the SSH keys, type ssh-keygen -t rsa -C "your_email@example.com". This will create both id_rsa and id_rsa.pub files.

    Add the id_rsa to ssh list on local computer: ssh-add ~/.ssh/id_rsa.

    After generating the keys get the pubkey using :

    cat ~/.ssh/id_rsa.pub 
    

    you will get something like :

    cat ~/.ssh/id_rsa.pub 
    
    ssh-rsa AAAB3NzaC1yc2EAAAADAQABAAACAQCvMzmFEUPvaA1AFEBH6zGIF3N6pVE2SJv9V1MHgEwk4C7xovdk7Lr4LDoqEcqxgeJftwWQWWVrWWf7q9qCdHTAanH2Q5vx5nZjLB+B7saksehVOPWDR/MOSpVcr5bwIjf8dc8u5S8h24uBlguGkX+4lFJ+zwhiuwJlhykMvs5py1gD2hy+hvOs1Y17JPWhVVesGV3tlmtbfVolEiv9KShgkk3Hq56fyl+QmPzX1jya4TIC3k55FTzwRWBd+IpblbrGlrIBS6hvpHQpgUs47nSHLEHTn0Xmn6Q== user@email.com
    

    copy this key (value) and go to github.com and under the setting (ssh and pgp key) add your public key.

    0 讨论(0)
  • 2020-11-22 05:23

    Go to your GitHub account dashboard, find your project repository, click Settings tab - under Deploy keys you'll have to add your SSH key. Open Terminal and type:

    cat ~/.ssh/id_rsa.pub | pbcopy 
    

    This will copy the key from your id_rsa.pub file. So just go back to GitHub dashboard, paste it, click Add Key and that's it.

    The same solution applies to Bitbucket accounts.

    0 讨论(0)
  • 2020-11-22 05:27

    I had the same issue recently. This might help if you need a fix immediately, but this needs to be done every time you re-start your system

    From terminal, run : ssh-add ~/.ssh/id_rsa

    Enter your system password and that should work.

    0 讨论(0)
  • 2020-11-22 05:28

    In case you are not accessing your own repository, or cloning inside a cloned repository (using some "git submodule... " commands):

    In the home directory of your repository:

    $ ls -a
    

    1. Open ".gitmodules", and you will find something like this:

    [submodule "XXX"]
        path = XXX
        url = git@github.com:YYY/XXX.git
    

    Change the last line to be the HTTPS of the repository you need to pull:

    [submodule "XXX"]
        path = XXX
        https://github.com/YYY/XXX.git
    

    Save ".gitmodules", and run the command for submodules, and ".git" will be updated.

    2. Open ".git", go to "config" file, and you will find something like this:

    [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
    [remote "origin"]
        url = https://github.com/YYY/XXX.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "master"]
        remote = origin
        merge = refs/heads/master
    [submodule "XXX"]
        url = git@github.com:YYY/XXX.git
    

    Change the last line to be the HTTPS of the repository you need to pull:

        url = https://github.com/YYY/XXX.git
    

    So, in this case, the main problem is simply with the url. HTTPS of any repository can be found now on top of the repository page.

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