Git fatal : Could not read from remote repository 해결법

jjun._·2022년 5월 22일
3
post-thumbnail

Github repository를 생성한 후, 저장소 정보를 추가하고

"git push origin main"를 입력했다.

그런데 예상하지 못한 에러가 발생했다.

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

바로 구글링을 시작했다.

Github Docs에서 해결법을 찾았다.

SSH Key 생성

$ ssh-keygen -t ed25519 -C "your_email@example.com"
  1. 새로운 SSH key를 생성한다.
  • 만약, ed25591 알고리즘을 지원하지 않는 시스템이라면 다음을 입력한다.
    "$ ssh-keygen -t rsa -b 4096 -C 'your_email@example.com'"

입력 후 출력되는 것들은 [Enter]만 누르면 된다.

$ eval "$(ssh-agent -s)"
  > Agent pid 59566
$ ssh-add ~/.ssh/id_ed25519
  1. ssh-agent에 ssh키를 추가한다.

Github 계정에 SSH key 추가

  1. ~/.ssh 위치에 있는 id_ed25519.pub 파일을 열고 ssh key를 복사한다.

  1. Github 페이지 우측 상단 계정 아이콘을 누르고 Settings로 들어간다.

  2. 사이드바 "Access" 섹션에 "SSH and GPG keys"를 클릭한다.

  1. 우측 상단 New SSH key 버튼을 누른다.

  1. Title은 마음대로 정하고, 밑에 Key 박스에 아까 복사해둔 ssh key를 붙여 넣는다.

  2. 그리고 Add SSH key 버튼을 누르면 끝.

SSH 연결 테스트

마지막으로 ssh 연결이 잘 되는지 테스트해본다.

$ ssh -T git@github.com

연결이 잘 된다면

> Hi username! You've successfully authenticated, but Github does not provie shell access.

성공이다.

만약 위처럼 뜨지 않고 에러가 발생한다면, 아래 링크를 참고해보자.

"Error: Permission denied(publickey)"

0개의 댓글