手順
SSHキー作成
※ mail@address.com
の部分は自分が登録したメールアドレスでお願いします。
ターミナルで以下の各Github用、Bitbucket用のコマンドを実行するしてSSHキーを作成する
ssh-keygen -t rsa -C mail@address.com -f ~/.ssh/id_rsa_github
ssh-keygen -t rsa -C mail@address.com -f ~/.ssh/id_rsa_bitbucket
各コマンドを実行すると、
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
と聞かれるのでパスフレーズを設定。
(設定しないでエンターキーだけ押してもできます)
lsコマンドでちゃんと作成されているか確認
$ ls ~/.ssh
config id_rsa_bitbucket.pub id_rsa_github.pub
id_rsa_bitbucket id_rsa_github
.ssh/configの設定を追加
以下を追加する
.ssh/config
Host github.com
User git
HostName github.com
IdentityFile ~/.ssh/id_rsa_github
IdentitiesOnly yes
Host bitbucket.org
User git
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_bitbucket
IdentitiesOnly yes
SSHキーを登録
各SSHキーの公開鍵を以下のコマンドでコピーして各Github、Bitbucketに登録
cat ~/.ssh/id_rsa_github.pub | pbcopy
cat ~/.ssh/id_rsa_bitbucket.pub | pbcopy
special thanks
以下を参考にさせていただきました。
http://www.task-notes.com/entry/20150210/1423537200
http://umi-uyura.hatenablog.com/entry/2016/05/17/233545