0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

公開鍵を複数作ってサイトによって変える(メモ)

Posted at

サイトによって公開鍵を変えたい

  • 登録してるメールアドレスがサイトによって違うから公開鍵何個か使い分けたい。

環境

  • mac
  • zshが標準シェル

公開鍵の作成と設置(1個目)

  1. terminal起動
  2. 以下コマンドでSSHキーの作成
$ ssh-keygen -C "自分のメールアドレス"

3. 以下のように好きなパスワードを作るように言われるので入力する(後でgithubとかからcloneしてくるときに求められるパスワードになる)

Enter passphrase (empty for no passphrase):  //パスワードを入力
Enter same passphrase again:  //再入力

4. 作った公開鍵をコピーする(これ等符号の向き間違えると公開鍵の内容が消える)

pbcopy < ~/.ssh/id_rsa.pub

5.今コピーした公開鍵を使いたいサイトの該当場所にペーストして登録してくる。

公開鍵の作成と設置(2個目)

  1. terminal起動
  2. ~/.ssh/ に移動
$ cd ~/.ssh/

3. 以下コマンドでSSHキーの作成

$ ssh-keygen -C "自分のメールアドレス(さっきと違うメールのハズ)"

4. 1個めの公開鍵と違う名前のファイルに2個目の鍵を保存しないといけないので、2個目の鍵用のファイル名前を好きに付ける(xxxxの部分)

Enter file in which to save the key (/Users/ts/.ssh/id_rsa): xxxxxx

5. 以下のように好きなパスワードを作るように言われるので入力する(後でgithubとかからcloneしてくるときに求められるパスワードになる)

Enter passphrase (empty for no passphrase):  //パスワードを入力
Enter same passphrase again:  //再入力

6. 作った公開鍵をコピーする(等符号の向き間違えると公開鍵の内容が消える)

pbcopy < ~/.ssh/xxxxxx

7. 今コピーした公開鍵を使いたいサイトの該当場所にペーストして登録してくる。

どっちサイトでどっちの鍵使ってるのかmacに教えてあげる

  1. config開く
vim ~/.ssh/config

2. 以下のような感じで入力して保存

例:

Host amazon.com                 //サイトのドメイン(1個目)
    User yamadataro             //サイトでのユーザー名
    IdentityFile ~/.ssh/id_rsa   //このサイトに登録した鍵のファイルパス
    IdentitiesOnly yes
Host github.com                                  //サイトのドメイン(2個目)
    User yamada                 //サイトでのユーザー名
    IdentityFile ~/.ssh/xxxxxx  //このサイトに登録した鍵のファイルパス
    IdentitiesOnly yes

【参考】
vim開いたら、
i ... 入力できるようになる
:q ... 保存せずに閉じる
:wq ... 保存して閉じる
escキー ... 入力やめる

3. terminalを完全に閉じてまた立ち上げ直す。

おしまい

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?