ssh-add -l로 확인할 수 있고 ssh-add -d ~/.ssh/id_rsa 명령어로 제거할 수 있습니다.
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 설정
~/.ssh/config 파일을 아래와 같이 생성합니다.
# account1 github
Host github.com
HostName github.com
User git
AddKeyToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
# account2 github
Host github.com-acc2
HostName github.com
User git
AddKeyToAgent yes
UseKeychain yes #재부팅 시 키 설정을 유지해줍니다.
IdentityFile ~/.ssh/id_rsa_acc2
git global config를 아래와 같이 설정합니다.
# for account1
git config --global user.name "acc2_username" #github에서 사용하는 이름
git config --global user.email "account2@gmail.com"
# for account2: nothing to do
로컬 폴더마다 다른 깃헙 계정을 연동하기 위해서는 해당 폴더에서 git init 후 --global flag 없이 위 내용 설정하면 됨
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.
연결확인
ssh -T git@github.com
ssh -T git@github.com-acc2
Github Repository 연결
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 add origin git@github.com-acc2:acc2_username/reponame.git # 생성시
git remote set-url origin git@github.com-acc2:acc2_username/reponame.git # 변경시