個人用、会社用とGitHubのアカウントが複数ある人向け。昔設定したのにもう忘れてしまったのでメモ。
現状確認
shuka@saito ~ $ cd ~/.ssh/
shuka@saito ~/.ssh $ ls
id_rsa.pub id_rsa
秘密鍵・公開鍵が1ペアで存在していますね。
もう1つの鍵を生成
既にある鍵のペアを1つのアカウントに利用するとして、もう1つのアカウントを紐付けるための秘密鍵・公開鍵を生成します。
shuka@saito ~/.ssh $ ssh-keygen -t rsa -C "cancolle_sub@pfcolle.com" -f github_sub_id_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in github_sub_id_rsa.
Your public key has been saved in github_sub_id_rsa.pub.
あとはsshのconfigを編集して終わり
shuka@saito ~/.ssh $ vim config
~/.ssh/configの内容(例)
# github_office
Host github-saito
User git
Port 22
HostName github.com
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive yes
IdentitiesOnly yes
#github_private
Host github-shuka
User git
Port 22
HostName github.com
IdentityFile ~/.ssh/github_sub_id_rsa
TCPKeepAlive yes
IdentitiesOnly yes
このあと、ディレクトリ毎にGitの情報を変更したい場合(例えば、会社用は本名、プライベート用は個人みたいな)は下記の記事をご参照ください。