LoginSignup
3
3

More than 5 years have passed since last update.

GithubとBitbucketで使うSSHキーを別々に作ってみる

Last updated at Posted at 2017-06-15

手順

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

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3