aws에서 새로운 인스턴스를 만들고 git을 연동하다 보면 꼭 마주치는 에러다.

[ec2-user@doolda]$ git push 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.

간단히 git에 ssh key를 추가해줌으로써 손쉽게 해결할 수 있다.

ssh key 생성하기

$ ssh-keygen -t rsa -C "{your-github-email}"
/ / 이후 엔터 3번

정상적으로 생성되었다면 public key, fingerprint 등 이것저것 만들었다는 안내 문구가 출력될 것이다.

다음 명령을 통해 우리가 필요한 ssh key를 출력한다.

$ cat ~/.ssh/id_rsa.pub

출력된 정상적인 ssh key는 ssh-rsa로 시작해서 위에서 입력한 {your-github-email}로 끝날 것이다.

ssh-rsa 부터 이메일 끝까지 모두 복사해둔다.

github에 생성한 ssh key 등록하기

  1. 본인의 github 계정의 Settings로 들어간다.
    image
  2. `SSH and GPG keys 탭으로 이동
    image
  3. New SSH Key 클릭
    image
  4. Key에다 복사해둔 ssh key를 입력하고 Title은 맘에 드는 이름을 지어주자.
    image
    Add SSH Key를 누르고 비밀번호를 입력하라는 창이 뜨면 입력해준다.

끝났다. 이제 다시 (아마도)git push origin master 명령을 수행해보면 정상적으로 동작할 것이다.

+ Recent posts