Nice programing

GitHub 오류 메시지-권한이 거부되었습니다 (공개 키).

nicepro 2020. 9. 30. 11:28
반응형

GitHub 오류 메시지-권한이 거부되었습니다 (공개 키).


누구든지이 오류를보고 무엇을해야하는지 알고 있습니까?

터미널을 사용하고 있으며 루트에 있고 GitHub 저장소가 존재하며 지금 무엇을해야할지 모르겠습니다.

> 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.

GitHub에서 사용자를 인증 할 수 없습니다. 따라서 머신에 SSH 키를 설정 하지 않았기 때문에 SSH 키를 설정 하지 않았 거나 키가 GitHub 계정과 연결되어 있지 않습니다.

SSH / git URL 대신 HTTPS URL을 사용하여 SSH 키를 처리하지 않아도됩니다. 이것은 GitHub에서 권장하는 방법 입니다.

또한 GitHub에는 해당 오류 메시지에 대한 도움말 페이지 가 있으며 확인할 수있는 모든 내용을 자세히 설명합니다.


~ / .ssh 디렉토리에 구성 파일 을 만들었습니까 ? 다음과 같은 내용이 있어야합니다.

Host github.com 
 IdentityFile ~/.ssh/github_rsa

github_rsa 라는 ssh 키를 만들었다 고 가정합니다.

GitHub에 업로드했습니다 ...

참고 : ~ / .ssh / 디렉토리에 둘 이상의 키 (2 개 이상)가있는 경우 이러한 명시 적 구성 방법을 따라야합니다. 이 방법으로 키를 지정하지 않으면 순서대로 첫 번째 키를 가져 와서 github 인증에 사용하므로 키 파일 이름에 따라 달라집니다.


SSH 키 (없는 경우)를 생성하고 공개 키를 Github 계정과 연결해야합니다. Github의 자체 문서를 참조하십시오 .


나는이 문제를 알고있다. ssh 키를 추가 한 후 ssh 에이전트에도 ssh 키를 추가합니다 (oficial 문서 https://help.github.com/articles/generating-ssh-keys/에서 )

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

그 후에 모든 것이 잘 작동하고 git은 적절한 키를 볼 수 없습니다.


이것은 나에게 일어난 일입니다. 어떤 이유로 나의 기원은 내가 깨닫지 못한 채 엉망이되었다.

설정이 여전히 올바른지 확인하십시오.

git remote -v

URL은 ssh : //git@github.com/YourDirectory/YourProject.git와 같은 형식이어야합니다. git@github.com이 보이지 않으면

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

바로 설정합니다. 또는 github 앱을 사용하여 특정 저장소의 설정 패널에서 기본 원격 저장소 URL을 확인하고 설정할 수 있습니다.


SSH를 통해 GitHub를 연결한다고 가정하면 아래 명령을 실행하여이를 확인할 수 있습니다.

$git config --get remote.origin.url

결과가 git@github.com : xxx / xxx.github.com.git 형식으로 표시되면 다음을 수행해야합니다.

SSH 키를 생성하거나 기존 키를 사용합니다. 키가있는 경우 ssh-agent (2 단계) 및 GitHub 계정 (3 단계)에 키를 추가하기 만하면됩니다.

아래는 SSH 키가없는 분들을위한 것입니다.

1 단계 공개 / 개인 rsa 키 쌍 생성.

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

SSH 키를 저장할 위치와 사용하려는 암호를 확인하라는 메시지가 표시됩니다.

2 단계 ssh-agent에 키 추가

  • ssh-agent가 활성화되어 있는지 확인하십시오.

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

  • SSH 키를 ssh-agent에 추가합니다.

    $ssh-add ~/.ssh/id_rsa

3 단계 계정에 SSH 키 추가

$sudo apt-get install xclip

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

그런 다음 복사 한 키를 GitHub에 추가합니다.

이동 설정 -> SSH 키 (개인 설정 사이드 바) -> SSH 키를 추가 -> 양식을 작성 (키가 클립 보드에, 그냥 사용 CTRL + V) -> 추가 키

위의 단계를 거친 후 권한 문제를 해결해야합니다.

참조 링크 : SSH 키 생성 .


먼저 컴퓨터의 기존 ssh 키를 확인해야합니다. 터미널을 열고 다음을 실행하십시오.

ls -al ~/.ssh

#or

cd ~/.ssh
ls

그러면 .ssh 디렉토리에있는 파일이 나열됩니다.

그리고 마지막으로 당신이 보는 것에 따라 (제 경우에는) :

 github_rsa  github_rsa.pub known_hosts

RSA를 설정하면 "git push origin"문제를 해결할 수 있습니다.

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

참고 : RSA 인증서는 키 쌍이므로 개인 및 공용 인증서를 갖게됩니다. 개인 인증서는 github (이 경우)에 속하기 때문에 액세스 할 수 없지만이 오류가 발생하면 공용 인증서가 누락 될 수 있습니다. (적어도 그게 내 경우 였고, 내 github 계정이나 저장소가 어떻게 든 엉망이되어 이전에 생성 된 공개 키를 "연결"해야했습니다)


이 오류가 발생했습니다. 방금 OSX를 Sierra로 업그레이드했고 이전 키가 더 이상 등록되지 않은 것으로 나타났습니다.

처음에는 "macOS Sierra로 업그레이드하면 SSH 키가 손상되고 자신의 서버에서 잠 깁니다." 라고 생각했습니다.

그러나 나는 그것을 피했다. 기존 키를 다시 등록해야했습니다.

ssh-add -K

그리고 암호를 입력하세요 ... 완료!


자신의 저장소에 액세스하지 않거나 복제 된 저장소 내부에서 복제하지 않는 경우 (일부 "git submodule ..."명령 사용) :

저장소의 홈 디렉토리에서 :

$ ls -a

1. ".gitmodules"를 열면 다음과 같은 것을 찾을 수 있습니다.

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

마지막 줄 을 가져와야하는 저장소 HTTPS변경합니다 .

[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.


Make sure ssh-add -l shows a fingerprint of an SSH key that's present in the list of SSH keys in your Github account.

If the output is empty, but you know you have a private SSH key that works with your github account, run ssh-add on this key (found in ~/.ssh. It's named id_rsa by default, so you'll likely run ssh-add id_rsa).

Else, follow these instructions to generate an SSH key pair .


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.


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!


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!! :)


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 to create the key in /home/root/.ssh/

$ sudo su
$ ssh-keygen
$ cd ~/.ssh
$ cat id_rsa.pub

Then copy the key in your github account. It's worked for me. You can try it.


If you have already created an SSH key and are still getting the error it is because you need to give the user permissions to read and write to the folder you are cloning into. To do this, sudo chmod 777 <your_folder_name_here>". 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 to this use admin in Windows if you're using the git bash


Issue solved if you change the ssh access to https access to the remote repository:

git remote set-url origin https_link_to_repository

git push -u origin master

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.


I would like to 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 default path for SSH key.

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


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

  • make sure you keys are present, by default another ~/.ssh/ folder, i.e. id.rsa and id.rsa.pub

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

    chmod 600 ~/.ssh/id_rsa

    chmod 644 ~/.ssh/id_rsa.pub

  • make sure the content 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


If you are using the GitHub for Mac UI, check preferences to make sure you're logged in.


I was getting same error during 'git push'. In client side I had two origin and master. I removed one, then it worked fine.


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.


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.


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.


Once scenario where this will happen is when you follow GitHub instructions after you create your repository. Git will instruct you to add your remote with something like this.

git remote add origin git@github.com:<user>/<project>.git

Replace what's in <> with values related to your account.

The solution is to remove the .git suffix. Add the remote as follows:

git remote add origin git@github.com:<user>/<project>


tl;dr

in ~/.ssh/config put

PubkeyAcceptedKeyTypes=+ssh-dss

Scenario If you are using a version of openSSH > 7, like say on a touchbar MacBook Pro it is ssh -V
OpenSSH_7.4p1, LibreSSL 2.5.0

You also had an older Mac which originally had your key you put onto Github, it's possible that is using an id_dsa key. OpenSSH v7 doesn't put in by default the use of these DSA keys (which include this ssh-dss) , but you can still add it back by putting the following code into your ~/.ssh/config

PubkeyAcceptedKeyTypes=+ssh-dss

Source that worked for me is this Gentoo newsletter

Now you can at least use GitHub and then fix your keys to RSA.


Maybe your ssh-agent is not enable You can try it

  1. Download git

http://git-scm.com/

  1. Install it

  2. Enable ssh-agent

C:\Program Files\Git\cmd

start-ssh-agent


For me I tried this -

eval "$(ssh-agent -s)"

then I run

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

and for generating the key you can run

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

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

you can store this key to github for more read this Adding a new SSH key to your GitHub account

I hope it will help others :)


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.


I had 2 Github identity files loaded in the ssh agent. My personal key and another for a client project.

I removed the key that was causing confusion:

ssh-add -d id_rsa_github_somekey

참고URL : https://stackoverflow.com/questions/12940626/github-error-message-permission-denied-publickey

반응형