LoginSignup
9
9

More than 5 years have passed since last update.

GitHubに公開鍵を登録する

Posted at

GitHubでは作成したリポジトリへのアクセス認証をSSHを利用した公開鍵認証で行います。

SSH Keyの作成

次のように実行します。

$ ssh-keygen -t rsa -C "#メールアドレス#"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxx/.ssh/id_rsa):#Enterを押す#
Created directory '/c/Users/xxxx/.ssh'.
Enter passphrase (empty for no passphrase):#パスワードを入力#
Enter same passphrase again:#再度パスワードを入力#
Your identification has been saved in /c/Users/xxxx/.ssh/id_rsa.
Your public key has been saved in /c/Users/xxxx/.ssh/id_rsa.pub.
The key fingerprint is:
#フィンガープリント# inakadegaebal@gmail.com
The key's randomart image is:
略

「C:\Users\ユーザー名\.ssh」フォルダーに

  • id_rsa
  • id_rsa.pub

というファイルが生成されます。ファイル名からわかるように、拡張子がpubになっているのが公開鍵、そうではないファイルが秘密鍵になります。

公開鍵の登録

GitHubの「Personal Settion」→「SSH Keys」から登録ができます。画面のボタンやリンク先の位置などはいつ変わるかわからないので書かないようにします。すぐ見つかると思います。
登録画面で「Title」欄にはユーザーが識別しやすいように名前を付けるだけなので何かわかりやすい名前を付けましょう。「Key」欄には生成した公開鍵を入れましょう。「id_rsa.pub」の内容をそのままコピペすれば大丈夫です。

確認

公開鍵の登録が終わったら、GitHubとの認証と通信ができるようになったか確認してみましょう。

$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.252.130)' can't be established.
RSA key fingerprint is #フィンガープリント#.
Are you sure you want to continue connecting (yes/no)? #yesを入力#
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/JEONG/.ssh/id_rsa':#パスワードを入力#

次のようなメッセージが表示されれば成功です。

Hi inakadegaebal! You've successfully authenticated, but GitHub does not provide shell access.
9
9
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
9
9