How to solve Permission denied (publickey) error when using Git?

后端 未结 30 1842
野性不改
野性不改 2020-11-22 08:07

I\'m on Mac Snow Leopard and I just installed git.

I just tried

git clone git@thechaw.com:cakebook.git

but that gives

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

    Visual guide (Windows)

    1 of 2. Git batch side

    1.1. Open git batch (Download her)

    1.2. Paste the text below (Change to your GitHub account email)

    $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    

    1.3. Press Enter (Accepts the default file location)

    1.4. Click Enter Twice (Or set SSH key passphrases - Gitbub passphrases docs)

    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]
    

    1.5. The key generate:

    Your identification has been saved in /c/Users/user/.ssh/id_rsa...

    1.6. Copy the SSH key to your clipboard.

    $ clip < ~/.ssh/id_rsa.pub

    2 of 2. Github website user side

    Under user setting Create key:

    Paste the code from step 1.6

    Done :)


    If someone doesn't want to use SSH use HTTPS :

    Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

    0 讨论(0)
  • 2020-11-22 08:12

    The github help link helped me sort out this problem. Looks like the ssh key was not added to the ssh-agent. This is what i ended up doing.

    Command 1:

    Ensure ssh-agent is enabled. The command starts the ssh-agent in the background:

    eval "$(ssh-agent -s)"
    

    Command 2:

    Add your SSH key to the ssh-agent:

    ssh-add ~/.ssh/id_rsa
    
    0 讨论(0)
  • 2020-11-22 08:12

    If you have more than one key you may need to do ssh-add private-keyfile

    0 讨论(0)
  • 2020-11-22 08:15

    Got same error report.

    Fixed with using HTTP instead. Since I don't want set "SSH keys" for a test PC.

    Change URL to HTTP when clone:

    git clone https://github.com/USERNAME/REPOSITORY.git
    

    My problem is a little bit different: I have URL set when adding a existing local repo to remote, by using:

    git remote add origin ssh://github.com/USERNAME/REPOSITORY.git
    

    To fix it, reset URL to HTTP:

    git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
    

    BTW, you may check your URL using command:

    git remote -v
    origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
    origin  https://github.com/USERNAME/REPOSITORY.git (push)
    

    Hope this will help some one like me. :D

    0 讨论(0)
  • 2020-11-22 08:15

    I met the same issue because of I was thought the difference between SSH and HTTPS is

    https://github.com/USERNAME/REPOSITORY.git

    ssh://github.com/USERNAME/REPOSITORY.git

    So I changed from HTTPS to SSH just by changing https:// to ssh:// nothing on the end of the url was changed.

    But the truth is:

    https://github.com/USERNAME/REPOSITORY.git
    
    git@github.com:USERNAME/REPOSITORY.git
    

    Which means I changed ssh://github.com/USERNAME/REPOSITORY.git to git@github.com:USERNAME/REPOSITORY.git it works.

    Stupid error but hope helps someone!

    0 讨论(0)
  • 2020-11-22 08:16

    I was getting the same error. My problem was mixing in sudo.

    I couldn't create the directory I was cloning into automatically without prefixing the git clone command with sudo. When I did that, however, my ssh keys where not being properly referenced.

    To fix it, I set permissions via chmod on the parent directory I wanted to contain my clone so I could write to it. Then I ran git clone WITHOUT a sudo prefix. It then worked! I changed the permissions back after that. Done.

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