Nice programing

Git을 사용할 때 Permission denied (publickey) 오류를 해결하는 방법은 무엇입니까?

nicepro 2020. 10. 3. 11:48
반응형

Git을 사용할 때 Permission denied (publickey) 오류를 해결하는 방법은 무엇입니까?


저는 Mac Snow Leopard를 사용 중이며 git.

나는 방금 시도했다

git clone git@thechaw.com:cakebook.git

하지만이 오류가 발생합니다.

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

내가 무엇을 놓치고 있습니까?
나는 또한 ssh-keygenpassphase없이 시도했지만 여전히 같은 오류입니다.


사용자가 이전에 설정된 SSH 공개 / 개인 키 쌍을 생성하지 않았습니까?

이 정보는 theChaw에서 작동하지만 SSH pubkey 인증을 지원하는 다른 모든 git 저장소에 적용될 수 있습니다. ( 예를 들어 gitolite , gitlab 또는 github를 참조하십시오 .)

먼저 자신의 공개 / 개인 키 쌍 세트를 설정하여 시작하십시오. 이것은 DSA 또는 RSA를 사용할 수 있으므로 기본적으로 설정 한 모든 키가 작동합니다. 대부분의 시스템에서 ssh-keygen을 사용할 수 있습니다.

  • 먼저 .ssh 디렉토리로 cd하고 싶을 것입니다. 터미널을 열고 다음을 실행하십시오.

    cd ~/.ssh && ssh-keygen

  • 다음으로 이것을 클립 보드에 복사해야합니다.
    • OS X에서 실행 : cat id_rsa.pub | pbcopy
    • Linux에서 다음을 실행하십시오. cat id_rsa.pub | xclip
    • Windows (Cygwin / Git Bash를 통해)에서 다음을 실행하십시오. cat id_rsa.pub | clip
  • 웹 사이트를 통해 계정에 키를 추가하십시오.
  • 마지막으로 .gitconfig를 설정하십시오.
    • git config --global user.name "bob"
    • git config --global user.email bob@... (구성이 다시로드되었는지 확인하기 위해 명령 줄을 다시 시작하는 것을 잊지 마십시오)

복제하고 체크 아웃하는 것이 좋습니다.

자세한 정보는 https://help.github.com/articles/generating-ssh-keys 에서 찾을 수 있습니다 (@Lee Whitney에게 감사드립니다)-

사용자가 이전에 설정된 SSH 공개 / 개인 키 쌍을 생성 했습니까?

  • github 또는 gitlab 계정 설정에서 어떤 키가 승인되었는지 확인하십시오.
  • 로컬 컴퓨터에서 연결되어야하는 해당 개인 키를 알려줍니다.

eval $(ssh-agent -s)

열쇠가 어디에 있는지 알려주세요

ssh-add ~/.ssh/id_rsa


다음을 통해보다 광범위한 문제 해결 및 자동 수정을 수행 할 수 있습니다.

ssh -vT git@github.com

출처 : https://help.github.com/articles/error-permission-denied-publickey/


이 오류는 Git 읽기 전용 URL 대신 SSH URL (읽기 / 쓰기)에 액세스하지만 해당 저장소에 대한 쓰기 액세스 권한이없는 경우 발생할 수 있습니다.

때로는 서버에 배포와 같이 자신의 저장소를 복제하고 싶을 때가 있습니다. 이 경우 실제로 읽기 전용 액세스 만 필요합니다. 하지만 이것이 여러분의 저장소 이기 때문에 GitHub는 여러분이 선호하는 경우 SSH URL을 표시 할 수 있습니다. 이 상황에서 원격 호스트의 공개 키가 GitHub SSH 키에 없으면 액세스가 거부되며 이는 발생할 것으로 예상됩니다 .

이에 상응하는 경우는 SSH URL로 쓰기 액세스 권한이없는 다른 사람의 저장소를 복제하려고 할 때입니다.

즉, 저장소 만 복제하려는 경우https://github.com/{user_name}/{project_name}.git SSH URL ( git@github.com:{user_name}/{project_name}.git) 대신 HTTPS URL ( )을 사용하여 (불필요한) 공개 키 유효성 검사를 피하십시오.


업데이트 : GitHub는 현재 HTTPS를 기본 프로토콜로 표시하고 있으며 이로 인해 SSH URL의 오용 가능성을 줄일 수 있습니다.


github 도움말 링크 는이 문제를 해결하는 데 도움이되었습니다. ssh 키가 ssh-agent에 추가되지 않은 것 같습니다. 이것이 내가 한 일입니다.

명령 1 :

ssh-agent가 활성화되어 있는지 확인하십시오. 이 명령은 백그라운드에서 ssh-agent를 시작합니다.

eval "$(ssh-agent -s)"

명령 2 :

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

ssh-add ~/.ssh/id_rsa

이것은 나를 위해 작동합니다.

ssh-add ~/.ssh/id_rsa

동일한 오류 보고서를 받았습니다.

대신 HTTP를 사용하여 수정되었습니다. 테스트 PC에 "SSH 키"를 설정하고 싶지 않기 때문입니다.

복제시 URL을 HTTP로 변경 :

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

내 문제는 약간 다릅니다 : 기존 로컬 저장소를 원격에 추가 할 때 다음을 사용하여 URL을 설정했습니다.

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

이를 수정하려면 URL을 HTTP로 재설정하십시오.

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

BTW, 다음 명령을 사용하여 URL을 확인할 수 있습니다.

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

이것이 나 같은 사람을 도울 수 있기를 바랍니다. :디


(적어도 일부 프로젝트의 경우) ssh 키가있는 github 계정이 있어야합니다 .

인증 에이전트 ( ssh-add -l )에 나열된 키를
확인합니다 (표시되지 않는 경우 ssh-add / path / to / your / key를 사용하여 기존 키 중 하나를 추가합니다 (예 : ssh-add ~ /.ssh/id_rsa ))
(키가없는 경우 먼저 만듭니다. 참조 : http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html 또는 Google ssh-keygen)

github 계정과 연결된 키가 있는지 확인하려면 다음을 수행하십시오 .

이동 : https://github.com/settings/ssh

몇 분 전에 ssh-add -l 을 입력했을 때 본 해시 중 하나와 일치하는 해시 키가있는 키가 하나 이상 표시되어야합니다 .

그렇지 않은 경우 추가 한 다음 다시 시도하십시오.


나는 약간 다른 상황이 있었고 원격 서버에 로그온했고 서버에서 git을 사용하고 있었는데 git 명령을 실행했을 때 동일한 메시지를 받았습니다.

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

내가 고치는 방법은 내 Mac에서 / etc / ssh_config 파일을 변경하는 것이 었습니다. ...에서

ForwardAgent no 

...에

ForwardAgent yes

나는 내가 한 것과 같은 문제로 고심하고 있었고 저장소를 복제 할 수있었습니다. iMac대해이 절차를 따랐습니다 .

첫 번째 단계 : 공개 SSH 키가 이미 있는지 확인합니다.

  1. 터미널을 엽니 다.
  2. ls -al ~/.ssh기존 SSH 키가 있는지 확인하려면 입력 하십시오.

디렉토리 목록을 확인하여 이미 공개 SSH 키가 있는지 확인하십시오. 기본 공개는 다음 d_dsa.pub, id_ecdsa.pub, id_ed25519.pub, id_rsa.pub 중 하나입니다.

찾을 수없는 경우 2 단계로 이동하고 그렇지 않으면 3 단계를 따르십시오.

2 단계 : 공개 SSH 키 생성

  1. 터미널을 엽니 다.
  2. github에 사용하는 유효한 이메일 주소로 followong 명령을 입력하십시오. ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  3. 터미널에서 다음을 볼 수 Generating public/private rsa key pair있습니다. "Enter a file in which to save the key,"Enter 누르 라는 메시지가 표시되면 기본 파일 위치를 사용합니다. Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]다시 Enter 키를 누르 라는 메시지가 표시되면 프롬프트에서 보안 암호를 입력합니다.
  4. Enter passphrase (empty for no passphrase): [Type a passphrase]Enter same passphrase again: [Type passphrase again]다시 Enter 누르지 않으려면 Enter 누르십시오.

이것은 생성됩니다 id_rsa.pub

3 단계 : SSH 키를 ssh-agent에 추가

  1. 중간 유형 eval "$(ssh-agent -s)"
  2. SSH 키를 ssh-agent에 추가하십시오. 새 SSH 키를 생성하는 대신 기존 SSH 키를 사용하는 경우 명령의 id_rsa를 기존 개인 키 파일의 이름으로 바꿔야합니다. 이 명령을 입력하십시오$ ssh-add -K ~/.ssh/id_rsa

이제 SSH 키를 복사하고 github 계정에 추가하십시오.

  1. 터미널에서 ssh 파일 이름과 함께이 명령을 입력합니다. pbcopy < ~/.ssh/id_rsa.pub그러면 파일 이 클립 보드에 복사됩니다. 이제 github 계정을 엽니 다. 설정> SSH 및 GPG 키> 새 SSH 키로 이동합니다. 제목을 입력하고 클립 보드에서 키를 붙여넣고 저장합니다. 완성되었습니다.

나는 차이점 생각되었다 때문에 같은 문제를 만났다 SSHHTTPS가 있다

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

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

그래서 URL 끝 에서 아무것도 변경 하지 않고 HTTPS 에서 SSH 로 변경했습니다.https://ssh://

그러나 진실은 :

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

git@github.com:USERNAME/REPOSITORY.git

, 작동 ssh://github.com/USERNAME/REPOSITORY.git하도록 변경 git@github.com:USERNAME/REPOSITORY.git했습니다.

어리석은 오류이지만 희망은 누군가를 돕습니다!


기본 GIT 지침은 SSH 키 항목을 참조하지 않았습니다. 위의 링크 중 일부를 따라 다양한 운영 체제에서이 작업을 수행하는 방법을 단계별로 정확히 설명하는 git 도움말 페이지를 찾았습니다 (링크는 이에 따라 OS를 감지하고 리디렉션합니다).

http://help.github.com/set-up-git-redirect/

GITHub에 필요한 모든 것을 안내하고 "RSA 키를 만들 때 암호를 추가하는 이유"와 같은 자세한 설명도 제공합니다. 다른 사람에게 도움이 될 경우를 대비하여 게시 할 것이라고 생각했습니다.


On Windows, make sure all your apps agree on HOME. Msys will surprisingly NOT do it for you. I had to set an environment variable because ssh and git couldn't seem to agree on where my .ssh directory was.


Are you in a corporate environment? Is it possible that your system variables have recently changed? Per this SO answer, ssh keys live at %HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa.pub. So if %HOMEDRIVE% recently changed, git doesn't know where to look for your key, and thus all of the authentication stuff.

Try running ssh -vT git@github.com. Take note of where the identity file is located. For me, that was pointing not to my normal \Users\MyLogin but rather to a network drive, because of a change to environment variables pushed at the network level.

해결책? 내 새 %HOMEDRIVE%파일에는 로컬 파일과 동일한 권한이 있기 때문에 .ssh 폴더를 그곳으로 옮기고 하루를 불렀습니다.


여러분, 이것이 나를 위해 일한 방법입니다.

1- 터미널을 열고 사용자로 이동 [첨부 된 이미지보기]

2- .ssh 폴더를 열고 id_rsa 또는 id_rsa.pub와 같은 파일이 없는지 확인하십시오. 그렇지 않으면 파일을 제대로 다시 작성하지 못할 수 있습니다.

3-git --version [git 설치 및 버전 확인]

4- git config --global user.email "your email id"

5- git config --global user.name "your name"

6- git config --list [이름과 이메일을 설정했는지 확인]

7- cd ~ / .ssh

8- ssh-keygen, 파일 저장을 요청하고 허용

9- cat ~ / .ssh / id_rsa.pub [공개 키에 액세스하고 키를 gerrit 설정에 복사]

Note: You should not be using the sudo command with Git. If you have a very good reason you must use sudo, then ensure you are using it with every command (it's probably just better to use su to get a shell as root at that point). If you generate SSH keys without sudo and then try to use a command like sudo git push, you won't be using the same keys that you generated

enter image description here

enter image description here


One of the easiest way

go to terminal-

  git push <Git Remote path> --all

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

  • type id_rsa.pub | clip

Refs:


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


I have just experienced this issue while setting my current project, and none of the above solution works. so i tried looking what's really happening on the debug list using the command ssh -vT git@github.com. I notice that my private key filename is not on the list. so renaming the private key filename to 'id_rsa' do the job. hope this could help.


Its pretty straight forward. Type the below command

ssh-keygen -t rsa -b 4096 -C "youremailid@yourdomain.com"

Generate the SSH key. Open the file and copy the contents. Go to GitHub setting page , and click on SSH key . Click on Add new SSH key, and paste the contents here. That's it :) You shouldn't see the issue again.


I hit this error because I needed to give my present working directory permissions 700:

chmod -R 700 /home/ec2-user/

I was getting a similar Permission denied (publickey) error when trying to run a makefile.

As an alternative to the SSH steps above, you can Install the native GitHub for Mac application.

Click Download GitHub for Mac from - https://help.github.com/articles/set-up-git#platform-mac

Once you complete setup with your git hub account (I also installed the git hub command line tools but unsure if this step is required or not) then I received an email -

[GitHub] A new public key was added to your account

and my error was fixed.


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.


I was getting this error because I generated the ssh keys with the wrong email. I was able to connect using ssh, but not using git. The solution was to regenerate the keys using the main email address of my github account.


It worked for me.

Your public key is saved to the id_rsa.pub;file and is the key you upload to your account. You can save this key to the clipboard by running this:

pbcopy < ~/.ssh/id_rsa.pub

  • copy the SSH key to the clipboard, return to the web portal.
  • In the SSH Key field, paste your SSH key.
  • In the Name field, provide a name for the key.
  • save .

It worked for me

ssh -i [your id_rsa path] -T github@github.com

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

This strange error, in my case was a symptom of gnome-keyring-daemon incorrectly naming the key to which it required a password.

I follow the steps outlined here, and entered the password via the terminal. The error, aka the confounding GUI interface, was resolved. See: https://askubuntu.com/questions/3045/how-to-disable-gnome-keyring


In my case, I have reinstalled ubuntu and the user name is changed from previous. In this case the the generated ssh key also differs from the previous one.

The issue solved by just copy the current ssh public key, in the repository. The key will be available in your user's /home/.ssh/id_rsa.pub


In my MAC I solved this with:

cp ~/.ssh/github_rsa ~/.ssh/id_rsa

For some reason my git stopped to find the private key in the github_rsa file. This happened in a specific repo. I mean that in other repositories git kept working normally.

I think it's a bug.

I could find this behavior running ssh -vT git@github.com


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.

참고URL : https://stackoverflow.com/questions/2643502/how-to-solve-permission-denied-publickey-error-when-using-git

반응형