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-keygen -t ed25519 -C "your_email@example.com"
입력 후 출력되는 것들은 [Enter]만 누르면 된다.
$ eval "$(ssh-agent -s)"
> Agent pid 59566
$ ssh-add ~/.ssh/id_ed25519
Github 페이지 우측 상단 계정 아이콘을 누르고 Settings로 들어간다.
사이드바 "Access" 섹션에 "SSH and GPG keys"를 클릭한다.
Title은 마음대로 정하고, 밑에 Key 박스에 아까 복사해둔 ssh key를 붙여 넣는다.
그리고 Add SSH key 버튼을 누르면 끝.
마지막으로 ssh 연결이 잘 되는지 테스트해본다.
$ ssh -T git@github.com
연결이 잘 된다면
> Hi username! You've successfully authenticated, but Github does not provie shell access.
성공이다.
만약 위처럼 뜨지 않고 에러가 발생한다면, 아래 링크를 참고해보자.