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
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
右上の緑色のMake SHH Key をクリック
すると以下の画面が表示される
Title と Key を入力
・ Title = 何でも良い
・ Key = ターミナルへ移動し、以下のコマンドを入力するとKeyがコピーされる
$ pb copy < ~/.ssh/id_rsa.pub
Keyのブランクで⌘+vでペーストするとKeyが入力される。
あなたの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