GitHub Error Message - Permission denied (publicke

2019-01-01 07:47发布

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.

> git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

标签: git github
30条回答
何处买醉
2楼-- · 2019-01-01 08:26

Assuming you are connecting GitHub over SSH, you can run below command to confirm this.

$git config --get remote.origin.url

If you get a result has following format git@github.com:xxx/xxx.github.com.git, then you should do the following.

Generate a SSH key(or use existing one). if you had one, you just need to add your key to the ssh-agent (step 2)and to your GitHub account(step 3).

below are for those who don't have SSH key.

Step 1 Generating public/private rsa key pair.

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

You'll be asked to confirm where to save the SSH key and what passphrase you want to use.

Step 2 Add your key to the ssh-agent

  • Ensure ssh-agent is enabled

    $eval "$(ssh-agent -s)"

  • Add your SSH key to the ssh-agent:

    $ssh-add ~/.ssh/id_rsa

Step 3 Add your SSH key to your account

$sudo apt-get install xclip

$xclip -sel clip < ~/.ssh/id_rsa.pub

Then add the copied key to GitHub

Go to Settings->SSH keys(Personal settings side bar)->Add SSH key->fill out form(key is on your clipboard, just use ctrl+v)->Add key

After going through above steps, you should solve the permission problem.

Reference Link: Generating SSH keys.

查看更多
何处买醉
3楼-- · 2019-01-01 08:26

this worked for me:

1- remove all origins

git remote rm origin  

(cf. https://www.kernel.org/pub/software/scm/git/docs/git-remote.html)

*remote : "Manage the set of repositories ("remotes") whose branches you track.

*rm : "Remove the remote named . All remote-tracking branches and configuration settings for the remote are removed."

2- check all has been removed :

git remote -v  

3- add new origin master

git remote add origin git@github.com:YOUR-GIT/YOUR-REPO.git

that's all folks!

查看更多
公子世无双
4楼-- · 2019-01-01 08:26

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.

查看更多
孤独寂梦人
5楼-- · 2019-01-01 08:27

I was using github earlier for one of my php project. While using github, I was using ssh instead of https. I had my machine set up like that and every time I used to commit and push the code, it would ask me my rsa key password.

After some days, I stopped working on the php project and forgot my rsa password. Recently, I started working on a java project and moved to bitbucket. Since, I had forgotten the password and there is no way to recover it I guess, I decided to use the https(recommended) protocol for the new project and got the same error asked in the question.

How I solved it?

  1. Ran this command to tell my git to use https instead of ssh:

    git config --global url."https://".insteadOf git://
    
  2. Remove any remote if any

    git remote rm origin
    
  3. Redo everything from git init to git push and it works!

PS: I also un-installed ssh from my machine during the debug process thinking that, removing it will fix the problem. Yes I know!! :)

查看更多
十年一品温如言
6楼-- · 2019-01-01 08:28

you can use Https url to login

i guess you are trying to login with ssh url when you say git push if it as asking only password consider you are connecting through ssh.better you use http url.

查看更多
其实,你不懂
7楼-- · 2019-01-01 08:30

You need to generate an SSH key (if you don't have one) and associate the public key with your Github account. See Github's own documentation.

查看更多
登录 后发表回答