【GitHub】SSH接続の初回設定

以前、初回pushできたがディレクトリ構成がおかしなことになっていたため、再度トライ。またエラー表示出たので、メモしておきます。

 

「git init」してから初回SSH接続する際に

「git remote add origin <ssh接続用のコード>」まで問題なくいきましたが、最後pushすると下のようにエラー表示されました。

The authenticity of host 'github.com (52.69.186.44)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

 

どうやらSSH接続の設定が確立されていない?みたいなので、下の参考サイトを元にしてSSHキーの初回設定を行いました。

 

Enter file in which to save the key (/c/Users/<username>/.ssh/id_rsa): 
SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx <user>@<host>

 

対話(入力を求められる)を全てエンターキーで押すと上のようになって終了。

次に、「cat」コマンドでGitHubに登録する用の鍵を確認。

$ cat ~/.ssh/id_rsa.pub

このコマンドで出力されたキー(文字列)を全てコピー。

次に、GitHubのダッシュボードにいって、右上の個人アカウント設定用のアイコンをクリック→「Settings」をクリック→左側のパネルの「SSH and GPG keys」をクリック→「SSH keys」の段落の右側にある緑色のボタン「New SSH key」をクリック。

そうすると、登録する画面が出てくる。

上のtitle欄にはpushするデバイスの名前を他と区別がつくように分かりやすく記載。

下の欄にはコピーしたSSHキーをペースト。

 

で、登録完了。

無事にpushすることができました。

 

【参考サイト】

https://zenn.dev/cozftro/articles/2f841eaa83bd2a