GitHubに複数のアカウントを作ってひとつの端末から操作する
とある事情でGitHubに複数アカウントを持っていて、それを同じ端末から使いたかった。
GitHubのアカウントに登録するSSH公開鍵はGitHub全体で一意でなければならないらしく、同じSSH公開鍵を複数
のアカウントでつかいまわすことはできない。
解決方法はここに載っていた
要は、ssh-keygenで鍵をつくるときにデフォルトのid_rsaではなく何か適当な名前でつくってあげて、ssh-addで*1に認証鍵として追加してあげればいい。
$ ssh-keygen -t rsa -C 'ayumin@another' Generating public/private rsa key pair. Enter file in which to save the key (/Users/ayumin/.ssh/id_rsa): /Users/ayumin/.ssh/id_rsa_another Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/ayumin/.ssh/id_rsa_another. Your public key has been saved in /Users/ayumin/.ssh/id_rsa_another.pub. (略) $ ssh-add /Users/ayumin/.ssh/id_rsa_another
で、ホームディレクトリの .ssh/config に以下のように書く
#Default Github user Host github.com HostName github.com User git IdentityFile /Users/ayumin/.ssh/id_rsa # Another Github user Host github-another HostName github.com User git IdentityFile /Users/ayumin/.ssh/id_rsa_another
あとは id_rsa_another を使って認証したい方のアカウントの公開鍵として id_rsa_another.pub の中身をコピペすれば
$ git clone git@github-another:another/somethig.git
とかできるようになる。