https://yangeok.github.io/git/2020/03/08/ssh-multiple-account.html
이 글에 대부분이 나와 있지만 헷갈렸던 부분만 몇개 정리.
.ssh/config
에 아래와 같이 작성한다.
# 변경 전
# 개인용 계정
Host personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
# 회사용 계정
Host work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
그런데 Host를 저렇게 설정해 놓으니 자주 사용하는 work 계정도 git clone git@{Host}:{User}/{Repository}.git
할 때 매번 바꿔줘야 하는 점이 좀 그랬다.
그래서 자주 쓰는 work는 github.com
으로 해놓고 personal계정도 github.com-personal
로 설정해서, 복사한 ssh 주소 뒤에 -personal만 붙이면 되도록 했다.
# 변경 후
# 개인용 계정
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
# 회사용 계정
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
위 블로그에는 .gitconfig
에 아래처럼 작성하도록 되어 있었다.
[includeIf "gitdir:~/JOB/"]
path = .gitconfig-work
[includeIf "gitdir:~/TEST/"]
path = .gitconfig-personal
[includeIf "gitdir:~/Y/"]
path = .gitconfig-personal
그리고 나는 .gitconfig-work
, .gitconfig-personal
은 당연히 설정할 해당 디렉터리(JOB, TEST, Y같은..) 아래에 두는 것인줄 알았는데 path에서 그렇게 되도록 설정을 해주거나, 예시를 그대로 사용하고자 한다면.gitconfig
와 같은 디렉터리에 두어야 한다.