기존에 사용하던 계정과는 다른 계정의 github을 사용해야 할때가 있습니다.
회사 pc에는 회사 계정이 설정되어 있어 개인 계정을 사용하기 불편한데 이럴때 개인계정에 ssh key 설정을 해놓으면 편리합니다.
계정별로 파일이름을 지정해주는 것이 좋습니다.
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/kr1json/.ssh/id_rsa): /User/kr1json/.ssh/kr1json.github
private Key와 public Key가 생성됩니다. github에는 public Key를 등록하면 됩니다… github SSH Key 등록 방법 링크
$ ls ~/.ssh
kr1json.github kr1json.github.pub
Host github.com
User git
IdentityFile ~/.ssh/kr1json.github
AddKeysToAgent yes
UseKeychain yes
$ ssh -T git@github.com
Hi kr1json! You've successfully authenticated, but GitHub does not provide shell access.
remote url을 수정합니다.
...
[remote "origin"]
url = git@github.com:kr1json/kr1json.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
Host kr1json2.github.com
HostName github.com
User git
IdentityFile ~/.ssh/kr1json2.github
AddKeysToAgent yes
UseKeychain yes
...
[remote "origin"]
url = git@kr1json2.github.com:kr1json2/kr1json.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
-K
옵션은 MAC에서 재부팅해도 사용할수 있는 옵션
ssh-add -K keyfile