GITHUB 계정 두 개 이상 연동하기 (How to connect more than 2 Github Accounts in a computer)

Lightman·2022년 12월 7일
0

CS: GITHUB 🐱

목록 보기
3/3


Github에 계정을 연결하는 방법에는 HTTPs, SSH Key방법 두 가지가 있습니다. 여기에서는 그 중 SSH Key방법을 이용해 한 컴퓨터에서 두개 이상의 Github계정을 연동하여 사용하는 설정을 알아봅시다.

SSK Key 설정

  1. (선택) ~/.ssh에 있는 기존 SSH Key를 삭제합니다.
  2. 새로운 SSH Key(private & public)를 발급합니다.
    ssh-keygen -t rsa -b 4096 -C "account1@gmail.com"
    ssh-keygen -t rsa -b 4096 -C "account2@gmail.com"

이때, 파일명은 각각 ~/.ssh/id_rsa, ~/.ssh/id_rsa_acc2으로 저장합니다.

  1. ssh-agent를 시작하고 ssh에 private key들을 추가합니다.
    eval `ssh-agent`
    ssh-add -k ~/.ssh/id_rsa
    ssh-add -k ~/.ssh/id_rsa_acc2    

ssh-add -l로 확인할 수 있습니다

  1. github계정에 pulic key들을 추가합니다.
    cat ~/.ssh/id_rsa.pub | pbcopy 
    #Add it on GITHUB>SETTINGS>SSH and GPG keys>New SSH Key
    cat ~/.ssh/id_rsa_acc2.pub | pbcopy
    #Add it on GITHUB>SETTINGS>SSH and GPG keys>New SSH Key

config 설정

  1. ~/.ssh/config 파일을 아래와 같이 생성합니다.
  # account1 github
  Host github.com
  HostName github.com
  User git
  AddKeyToAgent yes
  IdentityFile ~/.ssh/id_rsa

  # account2 github
  Host github.com-acc2
  HostName github.com
  User git
  AddKeyToAgent yes
  IdentityFile ~/.ssh/id_rsa_acc2
  1. git global config를 아래와 같이 설정합니다.
	# for account1
    git config --global user.name "acc2_username"
    git config --global user.email "account2@gmail.com"
    # for account2: nothing to do

Github Repository 연결

  1. ssh config를 반영하여 ssh주소를 연결합니다.
    • github.com-acc2: githubHost, acc2_username: github id
  #WHEN YOU CLONING YOUR REPO with acc2
  git clone git@github.com-acc2:acc2_username/reponame.git

  #WHEN YOU MADE A LOCAL FOLDER AND CONNECT IT TO GITHUB with acc2
  git remote set-url origin git@github.com-acc2:acc2_username/reponame.git

(If you want to use multiple names and email addresses for different repositories, you can set up local configurations for each repository using the git config command without the --global flag. These local configurations will take precedence over the global configuration for that specific repository.)

  1. git push origin main 명령어를 이용하여 git에 push를 수행합니다.
profile
현직 데이터 분석가 / 데이터 과학의 정도를 따라 🚲 / About DEV DA ML

0개의 댓글