GitHub Error Message - Permission denied (publickey)

  • 7,000
  • Tác giả: admin
  • Ngày đăng:
  • Lượt xem: 7
  • Tình trạng: Còn hàng

GitHub isn't able đồ sộ authenticate you. So, either you aren't setup with an SSH key, because you haven't phối one up on your machine, or your key isn't associated with your GitHub tài khoản.

You can also use the HTTPS URL instead of the SSH/git URL đồ sộ avoid having đồ sộ khuyến mãi with SSH keys. This is GitHub's recommended method.

Further, GitHub has a help page specifically for that error message, and explains in more detail everything you could kiểm tra.

To solve it:

  1. You should have a public key in your trang chính directory, thus print the nội dung of your public key, in Linux distro run rẩy for example cat ~/.ssh/id_rsa.pub (if the prior doesn't work, kiểm tra the keys inside ~/.ssh/ with .pub extension)

  2. Add the nội dung of such a public key đồ sộ your Github account: click your profile photo -> Settings-> SSH and GPG keys -> New SSH key or Add SSH key

answered Oct 17, 2012 at 18:15

17

I know about this problem. After add ssh key, add you ssh key đồ sộ ssh agent too (from official docs

eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa

After it all work fine, git can view proper key, before couldn't.

You should replace id_rsa with your key.

Example: ssh-add ~/.ssh/id_rsa => ssh-add ~/.ssh/id_ed25511.pub

answered Jun 12, năm ngoái at 14:51

18

Did you create a config tệp tin in your ~/.ssh directory? It should have contents lượt thích these:

Host github.com 
 IdentityFile ~/.ssh/github_rsa

Assuming that you created an ssh key named github_rsa

and uploaded it đồ sộ GitHub...

NOTE: You must follow this way of explicit configuration if you have more than thở 1 key (2 and more) in your ~/.ssh/ directory. If you don't specify key this way, then first key in order is taken and used for github authentication, sánh it depends on the key tệp tin name then.

answered Feb 21, năm trước at 15:43

9

You need đồ sộ generate an SSH key (if you don't have one) and associate the public key with your Github tài khoản. See Github's own documentation.

answered Oct 17, 2012 at 18:13

4

This happened đồ sộ bầm. For some reason my origin got messed up without my realizing it:

Check if your settings are still correct

git remote -v

the url needs đồ sộ be something lượt thích ssh://[email protected]/YourDirectory/YourProject.git; if you don't see [email protected], use

git remote set-url origin git://github.com/YourDirectory/YourProject.git

to phối it right. Or you could use the github tiện ích đồ sộ kiểm tra and phối the Primary Remote Repository url in the settings panel of your particular repository.

answered May 23, 2013 at 3:30

2

Issue solved if you change the ssh access đồ sộ https access đồ sộ the remote repository:

git remote set-url origin https_link_to_repository

git push -u origin master

answered Nov 13, 2018 at 9:12

1

Assuming you are connecting GitHub over SSH, you can run rẩy below command đồ sộ confirm this.

$git config --get remote.origin.url

If you get a result has following format [email protected]:xxx/xxx.github.com.git, then you should tự the following.

Generate a SSH key(or use existing one). if you had one, you just need đồ sộ add your key đồ sộ the ssh-agent (step 2)and đồ sộ 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 "[email protected]"

You'll be asked đồ sộ confirm where đồ sộ save the SSH key and what passphrase you want đồ sộ use.

Step 2 Add your key đồ sộ the ssh-agent

  • Ensure ssh-agent is enabled

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

  • Add your SSH key đồ sộ the ssh-agent:

    $ssh-add ~/.ssh/id_rsa

Step 3 Add your SSH key đồ sộ your account

$sudo apt-get install xclip

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

Then add the copied key đồ sộ GitHub

Go đồ sộ 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.

answered Jan 3, năm 2016 at 14:34

2

Another solution :

create the SSH keys, type ssh-keygen -t rsa -C "[email protected]". This will create both id_rsa and id_rsa.pub files.

Add the id_rsa đồ sộ 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 lượt thích :

cat ~/.ssh/id_rsa.pub 

ssh-rsa AAAB3NzaC1yc2EAAAADAQABAAACAQCvMzmFEUPvaA1AFEBH6zGIF3N6pVE2SJv9V1MHgEwk4C7xovdk7Lr4LDoqEcqxgeJftwWQWWVrWWf7q9qCdHTAanH2Q5vx5nZjLB+B7saksehVOPWDR/MOSpVcr5bwIjf8dc8u5S8h24uBlguGkX+4lFJ+zwhiuwJlhykMvs5py1gD2hy+hvOs1Y17JPWhVVesGV3tlmtbfVolEiv9KShgkk3Hq56fyl+QmPzX1jya4TIC3k55FTzwRWBd+IpblbrGlrIBS6hvpHQpgUs47nSHLEHTn0Xmn6Q== [email protected]

copy this key (value) and go đồ sộ github.com and under the setting (ssh and pgp key) add your public key.

answered Aug 21, 2017 at 10:09

First, we need đồ sộ kiểm tra 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 sánh you will have a private and a public certificate, private will not be accessible for you since it belongs đồ sộ 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 tài khoản or repo got messed up somehow and i had đồ sộ "link" the public key, previously generated)

answered Aug 1, 2013 at 23:23

5

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 phối 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- kiểm tra all has been removed :

git remote -v  

3- add new origin master

git remote add origin [email protected]:YOUR-GIT/YOUR-REPO.git

that's all folks!

answered Dec trăng tròn, 2017 at 7:22

1

If you having issues đồ sộ make connection with your enterprise Github tài khoản then follow the below steps

Solution #1

ERROR: [email protected]: Permission denied (public key). fatal: Could not read
from remote repository. Please make sure you have the correct access
rights

Solution (OSX)

  • Open your terminal and follow below commands

  • $ cd ~

  • $ sudo su

  • $ ssh-keygen

    • Enter tệp tin in which đồ sộ save the key (/var/root/.ssh/id_rsa): $ id_rsa
    • Enter passphrase (empty for no passphrase): $ hit enter
    • Enter same passphrase again: $ hit enter
  • $ cd ~/.ssh

  • $ cat id_rsa.pub

  • copy display nội dung.

  • Open GitHub click your profile icon settings>SSH and GPC Keys

  • Click on the new ssh key button

  • enter any title and key that you copied

  • check now your issue is resolved

Solution #2

ERROR 2: remote: Password authentication is not available for Git operations.
remote: You must use a personal access token or SSH key.
remote: See https://github.compnay.com/settings/tokens or https://github.compnay.com/settings/ssh
fatal: unable đồ sộ access 'https://github.company.com/repo/app.git/': The requested URL returned an error: 403

Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

https://namespaceit.com/blog/remote-support-for-password-authentication-was-removed-on-august-13-2021-please-use-a-personal-access-token-instead

answered Nov 19, 2021 at 21:44

5

Yes I too had this question :/ I was going đồ sộ push my project đồ sộ Github in HTTP type(not in SSH type). I had đồ sộ enter my username and password in each push. So first I entered code relevant đồ sộ below type

git remote add origin [email protected]:YOUR-GIT/YOUR-REPO.git

and I got

[email protected]: Permission denied (publickey). fatal: Could not read from remote repository.

So however I solved my problems by doing below methods

  1. git remote rm origin remove your git remote repository
  2. git remote now kiểm tra whether your remote remote repository have been removed

URL = https://github.com//.git

  1. git remote add origin URL Again add your URL đồ sộ make remote repository
  2. git push -u origin master
    You can push your nội dung đồ sộ remote repository. In here as you use "-u" with the command you make a tracking branch and with the help of tracking branch in the remote repository you won't đồ sộ tell git what branch you push in the next steps :)
    And here if you use linux git will ask username and password before push the nội dung. And give your relevant credentials.

For prevent đồ sộ give username and password in each push you have đồ sộ change git config

For list your git config - git config --global --list
you will see

user.name=
user.email=

So you have đồ sộ add credential.helper attribute đồ sộ your git config to this

5.git config --global --add credential.helper store add this đồ sộ your terminal Now you can add new item đồ sộ your files then git add., git commit -m "", git push
And now too there git will request your username and password and that will be the last time. And for next git pushes git won't request username and password from you :)

answered May 29, 2021 at 14:03

I think i have the best answer for you, your git apps read your id_rsa.pub in root user directory

/home/root/.ssh/id_rsa.pub

That's why your key in /home/your_username/.ssh/id_rsa.pub can't be read by git. So you need đồ sộ create the key in /home/root/.ssh/

$ sudo su
$ ssh-keygen
$ cd ~/.ssh
$ mèo id_rsa.pub

Then copy the key in your github tài khoản. It's worked for bầm. You can try it.

answered Dec 1, năm ngoái at 11:16

1

Make sure ssh-add -l shows a fingerprint of an SSH key that's present in the list of SSH keys in your Github tài khoản.

If the output is empty, but you know you have a private SSH key that works with your github tài khoản, run rẩy ssh-add on this key (found in ~/.ssh. It's named id_rsa by mặc định, sánh you'll likely run rẩy ssh-add id_rsa).

Else, follow these instructions đồ sộ generate an SSH key pair .

answered Jun 10, năm trước at 21:07

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

In the trang chính directory of your repository:

$ ls -a

1. Open ".gitmodules", and you will find something lượt thích this:

[submodule "XXX"]
    path = XXX
    url = [email protected]:YYY/XXX.git

Change the last line đồ sộ be the HTTPS of the repository you need đồ sộ 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 đồ sộ "config" tệp tin, and you will find something lượt thích 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 = [email protected]:YYY/XXX.git

Change the last line đồ sộ be the HTTPS of the repository you need đồ sộ 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.

answered Jan 26, năm 2016 at 15:19

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 phối up lượt thích that and every time I used đồ sộ commit and push the code, it would ask bầm 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 đồ sộ bitbucket. Since, I had forgotten the password and there is no way đồ sộ recover it I guess, I decided đồ sộ 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 đồ sộ tell my git đồ sộ 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 đồ sộ 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!! :)

T J

43.1k13 gold badges86 silver badges142 bronze badges

answered Jan 1, năm 2016 at 6:23

1

OK there are few solutions đồ sộ this one, some of them might already been mentioned but just đồ sộ keep them together:

  • make sure you keys are present, by mặc định another ~/.ssh/ thư mục, i.e. id.rsa and id.rsa.pub

  • make sure the keys have correct permissions, you can run rẩy chmod:

    chmod 600 ~/.ssh/id_rsa

    chmod 644 ~/.ssh/id_rsa.pub

  • make sure the nội dung of you public key (id_rsa.pub) matches the one uploaded in the remote repository configuration

  • Finally fix the problems with ssh agent: ssh-add

Some more info: https://itcodehub.blogspot.com/2015/01/ssh-add-problems-with-ssh-agent-and.html

answered Mar 26, 2019 at 20:16

1

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

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

Enter your system password and that should work.

answered Feb 2, 2017 at 15:28

Allow write access for the key (identity) and then click Add key

If on Windows kiểm tra for more details in Using Github via SSH.

answered Jun 25, 2020 at 18:49

1

I would lượt thích đồ sộ add some of my findings:

If you are using GitBash, then make sure the SSH key is stored in ~/.ssh/id_rsa.

By Default GitBash searches for ~/.ssh/id_rsaas mặc định path for SSH key.

Even the tệp tin name id_rsa matters. If you save your SSH key in another filename or path, it will throw the Permission Denied(publickey)error.

answered Dec 24, năm 2016 at 10:10

If you have already created an SSH key and are still getting the error it is because you need đồ sộ give the user permissions đồ sộ read and write đồ sộ the thư mục you are cloning into. To tự this, sudo chmod 777 ". Of course, this is after you have generated an SSH key and you are still getting this error. Hope this helps future users.

Edit

To add on đồ sộ this use admin in Windows if you're using the git bash

answered Sep 8, năm 2016 at 19:52

3

TLDR:

  1. make sure you have write access đồ sộ the repo (configure it from the repo's settings).
  2. make sure the public key is in the SSH and GPG keys of your github tài khoản.

For bầm, this error usually occurs when I try đồ sộ clone some repo from a newly installed machine. When receiving a request, github will first kiểm tra the public key hash. If the public key does not match any user, github will reject this request. This case is common if the machine is new and your ssh key is newly generated.

answered Jan 5, 2022 at 3:16

4

Also in ubuntu, even though there was already SSH key entered in settings in BitBucket, I got this problem. The reason was, I was trying the following:

sudo git push origin master

Not sure why, but it got solved by using

git push origin master

No sudo used.

answered Feb 28, năm 2016 at 10:25

1

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

Just add the -E flag đồ sộ preseve the environment (your ~/.ssh/ path).

$ sudo -E git clone git@your_repo

From man sudo:

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

answered Feb 24, 2017 at 1:28

1

If you are using Widows-10, follow this instruction. It works for bầm.

  1. Open terminal as administrator

  2. run this command: "ssh-keygen". It generate a ssh key and will show the thư mục where it has been created. Check my image

  3. copy the generated "ssh key"

  4. go đồ sộ your github profile ---> settings --> Click SSH and GPH --> Click ""New SSH Key Button" and paste the "ssh key" and finally "clickthe add Button"

answered Dec 15, 2021 at 11:01

1

In case somebody else needs this. I created an ssh key with a different name lượt thích ar-2022-ssh in the user's .ssh thư mục. The problem with this is that Checking for existing SSH keys specifies that supported public keys for GitHub are one of the following.

id_rsa.pub
id_ecdsa.pub
id_ed25519.pub

Once I changed my ssh key name đồ sộ one of those when generating a key, it worked connecting đồ sộ GitHub

answered Jun 13, 2022 at 12:35

1

I faced the same problem.

[email protected]: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

You can track these steps if using the linux:

1. Check for existing SSH keys:

ls -al ~//.ssh/

2. Generate a new SSH key:

ssh-keygen -t ed25519 -C ""

3. Add your SSH key đồ sộ ssh agent:

eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_ed25519

4. Add your public SSH key đồ sộ your GitHub account:

cat < ~/.ssh/id_ed25519.pub

Now you are able đồ sộ push again.

answered Jun 11, 2023 at 17:14

you can use Https url đồ sộ login

i guess you are trying đồ sộ 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.

answered Jul 30, năm ngoái at 3:24

For bầm I tried this -

eval "$(ssh-agent -s)"

then I run rẩy

ssh-add ~/.ssh/path-to-the-keyfile

and for generating the key you can run rẩy

ssh-keygen -t rsa -b 4096 -C "[email protected]"

this will generate the pair of keys (Public and private).

you can store this key đồ sộ github for more read this Adding a new SSH key đồ sộ your GitHub account

I hope it will help others :)

answered Dec 8, năm 2016 at 10:52