GitHub 멀티 계정 사용을 위한 SSH key 등록 방법
Post

GitHub 멀티 계정 사용을 위한 SSH key 등록 방법

Problem

또 다른 github 계정에 기존 SSH key 를 등록하면 Key is already in use 메시지와 함께 중복 등록이 되지 않는다.

Cause

Github 는 이미 등록된 SSH Key 값 등록을 허용하지 않는다.
즉, 신규 계정 사용 시 새로운 SSH Key 값을 등록해 줘야 한다.

Solution

신규 SSH key 생성 후 Host 를 나눠서 계정 별로 각자의 Key를 바라보게 설정 해준다.

  1. 신규 키 생성
    1
    2
    3
    
    $ ssh-keygen -t rsa -b 4096 -C "another@example.com"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/niceharu/.ssh/id_rsa): id_rsa_another // 해당 값을 비우면 기존 키값을 덮어쓰므로 꼭 입력한다 !
    
  2. Github 신규 계정에 신규 Key를 등록
    ./ssh/id_rsa_another.pub 의 내용을 github 에 등록해 준다.

    Github SSH key 등록

  3. config 파일 생성 .ssh 폴더 아래 config 파일을 생성하여 아래 내용을 추가 해준다.
    1
    2
    3
    4
    5
    
    #신규 계정
    Host github.com-another
         HostName github.com
         User git
         IdentityFile ~/.ssh/id_rsa_another
    
  4. repository Host 변경
    이제 github의 Host를 구분하여 각각의 계정을 지정하여 사용할 수 있다.
TargetHost예시
기존 계정git@github.com git remote add origin git@github.com:myaccount/test.git
신규 계정git@github.com-anothergit remote add origin git@github.com-another:another/test.git