0
2

More than 3 years have passed since last update.

SSH key の取得とGithubとの接続方法

Posted at

SSH key の取得と接続方法

Step1: ターミナルを起動し .sshに移動

.ssh = ssh key を保存する場所

$ cd .ssh

Step2: SSH key の取得

$ ssh-keygen -t rsa -b 4096 -C "email@example.com"

"email@example.com" = "githubにサインインするemail"

Step3: パスワード設定を求められるので、設定(何でもよい)

*入力した文字は見えない

Enter passphrase (empty for no passphrase):

↓このようなランダムアートが出たらOK

スクリーンショット 2020-11-07 午後3.22.24.png

Step4: 取得したSSH keyをssh-agentに登録

$ eval "$(ssh-agent -s)"
Agent pid 88888
  • Agent pid 88888 = ランダムで5桁の数字が表示される
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /User/username/.ssh/id_rsa:

先程設定したパスワードを入力すると

Identity added: /User/username/.ssh/id_rsa (/User/username/.ssh/id_rsa)

↑この表示がでる。

Step 5: Githubアカウント上でSSH Keyを作成

githubアカウントのサインイン ー> settingへ移動 ー> SSH and GPG keys
スクリーンショット 2020-11-07 午後3.51.28.png

右上の緑色のMake SHH Key をクリック
スクリーンショット 2020-11-07 午後3.53.45.png
すると以下の画面が表示される

スクリーンショット 2020-11-07 午後3.55.20.png

Title と Key を入力
  ・ Title = 何でも良い
  ・ Key = ターミナルへ移動し、以下のコマンドを入力するとKeyがコピーされる

 $ pb copy < ~/.ssh/id_rsa.pub

Keyのブランクで⌘+vでペーストするとKeyが入力される。
スクリーンショット 2020-11-07 午後4.21.32.png

Add SSH Keyをクリック
スクリーンショット 2020-11-07 午後4.26.41.png

あなたのPCとGithubが接続された!

補足: 接続確認

$ ssh -T git@github.com

Hi username! You've successfully authenticated, but GitHub does not provide shell access.
が表示されたら上手く接続できている!

参考:
https://www.youtube.com/watch?v=H5qNpRGB7Qw&t=303s
https://qiita.com/shizuma/items/2b2f873a0034839e47ce

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