ID001 Dev Blog
TIL 6 분 소요

프로젝트별 GitHub 계정 분리하기 — SSH Key + Git Config

git github ssh

문제 상황

회사 계정과 개인 계정처럼 GitHub 계정이 여러 개일 때, 특정 프로젝트에서는 개인 계정으로 커밋하고 push하고 싶은 경우가 있다. 기본 설정만으로는 하나의 계정만 사용할 수 있어서 매번 충돌이 생긴다.

이 글에서는 SSH key 분리프로젝트별 git config로 이 문제를 깔끔하게 해결하는 방법을 정리한다.

핵심 개념

설정해야 할 것은 두 가지다.

설정역할영향 범위
SSH keypush/pull 시 어떤 GitHub 계정으로 인증할지네트워크 통신
git config user커밋에 찍히는 작성자 정보커밋 메타데이터

1단계 — SSH key 생성

개인 계정 전용 SSH key를 새로 만든다. 기존 key와 구분할 수 있도록 파일명을 명시적으로 지정한다.

ssh-keygen -t ed25519 -C "your-personal@email.com" -f ~/.ssh/id_ed25519_personal -N ""
  • -t ed25519: 빠르고 안전한 알고리즘
  • -f: 파일 경로 지정 (기존 key를 덮어쓰지 않음)
  • -N "": 패스프레이즈 없이 생성 (필요하면 설정)

2단계 — GitHub에 공개키 등록

생성된 공개키를 확인한다.

cat ~/.ssh/id_ed25519_personal.pub

출력된 키를 복사해서 GitHub에 등록한다.

  1. 개인 계정으로 GitHub SSH Keys 설정 접속
  2. New SSH key 클릭
  3. Title에 알아볼 수 있는 이름 입력 (예: MacBook Personal)
  4. Key에 공개키 붙여넣기
  5. Add SSH key

3단계 — SSH config에 호스트 별칭 등록

~/.ssh/config 파일에 개인 계정 전용 호스트 별칭을 추가한다.

# ~/.ssh/config

# 회사 계정 (기본)
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa

# 개인 계정
Host github-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_personal

핵심은 Host 이름을 다르게 지정하는 것이다. 실제로는 둘 다 github.com에 접속하지만, SSH는 호스트 이름으로 어떤 key를 사용할지 구분한다.

4단계 — 연결 확인

ssh -T github-personal
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.

이 메시지가 나오면 인증 성공이다.

5단계 — 프로젝트에 remote 설정

개인 계정의 레포지토리를 clone하거나 remote를 설정할 때, github.com 대신 위에서 정한 호스트 별칭 github-personal을 사용한다.

# 새로 clone할 때
git clone git@github-personal:your-username/your-repo.git

# 기존 프로젝트에 remote 추가할 때
git remote add origin git@github-personal:your-username/your-repo.git

# 기존 remote URL을 변경할 때
git remote set-url origin git@github-personal:your-username/your-repo.git

6단계 — 프로젝트별 git config 설정

해당 프로젝트 디렉토리에서 로컬 git config를 설정한다. --global 없이 실행하면 이 프로젝트에서만 적용된다.

cd /path/to/your-project
git config user.name "your-username"
git config user.email "your-personal@email.com"

설정 확인:

git config user.name   # your-username
git config user.email  # your-personal@email.com

전체 흐름 정리

1. SSH key 생성        → ~/.ssh/id_ed25519_personal
2. GitHub에 공개키 등록 → github.com/settings/keys
3. SSH config 별칭     → Host github-personal
4. remote URL 설정     → git@github-personal:user/repo.git
5. git config local    → user.name + user.email

이 설정이 완료되면 해당 프로젝트에서는 자동으로 개인 계정으로 인증되고, 커밋 author도 개인 계정으로 기록된다. 다른 프로젝트에는 영향을 주지 않는다.

기존 커밋의 author 변경

이미 다른 계정으로 작성된 커밋이 있고 아직 push 전이라면, rebase로 author를 일괄 변경할 수 있다.

git rebase --root --exec 'git commit --amend --no-edit --author="your-username <your-personal@email.com>"'