ssh를 사용해 git clone 하기

깃허브에서 클론 할 수 있는 방법 2가지(ssh, pat)를 정리한다

ssh로 클론

ssh key 생성

  • git bash를 실행하여 진행한다
git bash terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
# 새로운 ssh 키 생성
# 생성할 때 파일명과 비밀번호를 지정해 줄 수 있다
# 비밀번호는 입력하지 않는다 (엔터키로 스킵)
# 비밀번호까지 지정해주고 싶으면 아래 링크를 참고하자
# https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/working-with-ssh-key-passphrases
# -C 옵션 뒤에는 자신의 이메일 등 적고 싶은 문구를 적는다
# ssh-keygen -t ed25519 -C "chin_sung@naver.com"
ssh-keygen -t ed25519 -C "안녕하세요요요요요"

cd ~/.ssh
# 공개키 내용을 전부 복사한다
cat id_ed25519.pub
# output: ssh-ed25519 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx chin_sung@naver.com
  • 나는 기본값으로 생성했다
  • ~/.ssh/id_ed25519
  • ~/.ssh/id_ed25519.pub
  • .pub 파일이 이제 깃허브에 등록해야 하는 공개키이다
  • cat 명령으로 읽어서 복사해두자

ssh key 등록

참고

PAT으로 클론

terminal
1
2
# git clone https://{pat}@github.com/{username}/{repo}
git clone https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@github.com/chinsun9/my-private-repo.git
  • personal access token으로도 클론 할 수 있다. 자세히

perssonal access token으로 비공개 레포 git clone 하기

1
git clone https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@github.com/chinsun9/my-private-repo.git
1
2
3
4
git clone https://github.com/chinsun9/my-private-repo.git
Cloning into 'my-private-repo'...
Username for 'https://github.com': chinsun9
Password for 'https://chinsun9@github.com': xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  • 이런 식으로 패드워드 대용으로 사용해도 되지만,
  • github.com 앞에 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@
  • 토큰@를 붙여서 cli에서 입력하는 과정을 스킵할 수 있다
  • 이때 사용하는 토큰은 repo: Full control of private repositories 권한이 필요하다