How to solve Permission denied (publickey) error w

2018-12-31 18:35发布

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

I just tried

git clone git@thechaw.com:cakebook.git

but that gives me this error:

Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

What am I missing?
I've also tried doing ssh-keygen with no passphase but still same error.

30条回答
谁念西风独自凉
2楼-- · 2018-12-31 18:57

This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See gitolite, gitlab or github for example.)

First start by setting up your own public/private key pair set. This can use either DSA or RSA, so basically any key you setup will work. On most systems you can use ssh-keygen.

  • First you'll want to cd into your .ssh directory. Open up the terminal and run:

    cd ~/.ssh && ssh-keygen

  • Next you need to copy this to your clipboard.
    • On OS X run: cat id_rsa.pub | pbcopy
    • On Linux run: cat id_rsa.pub | xclip
    • On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip
  • Add your key to your account via the website.
  • Finally setup your .gitconfig.
    • git config --global user.name "bob"
    • git config --global user.email bob@... (don't forget to restart your command line to make sure the config is reloaded)

Thats it you should be good to clone and checkout.

Further information can be found on https://help.github.com/articles/generating-ssh-keys (thanks to @Lee Whitney)

查看更多
弹指情弦暗扣
3楼-- · 2018-12-31 18:57

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

查看更多
与风俱净
4楼-- · 2018-12-31 18:57

In addition to Rufinus' reply, the shortcut to copy your ssh key to the clipboard in Windows is:

  • type id_rsa.pub | clip

Refs:

查看更多
骚的不知所云
5楼-- · 2018-12-31 18:58

I had a slight different situation, I was logged on to a remote server and was using git on the server, when I ran any git command I got the same message

   Permission denied (publickey).
   fatal: The remote end hung up unexpectedly

The way I fixed it was by changing the file /etc/ssh_config on my Mac. from

ForwardAgent no 

to

ForwardAgent yes
查看更多
栀子花@的思念
6楼-- · 2018-12-31 18:58

Use the ssh link from Github but make sure to not append it with ssh just use what the ssh tab on git hub gives you to clone your repo.

查看更多
明月照影归
7楼-- · 2018-12-31 19:00

The easiest solution to this, when you are trying to push to a repository with a different username is:

 git remote set-url origin https://USERNAME@github.com/USERNAME/PROJECTNAME.git
查看更多
登录 后发表回答