git push時の'Permission denied (publickey)'というエラー
![kei](https://res.cloudinary.com/zenn/image/fetch/s--VpZayay6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/662f2db0f2.jpeg)
【実行したコマンド】
git remote add origin git@github.com:<username>/<repository>.git
git push -u origin main
【エラー内容】
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.
![kei](https://res.cloudinary.com/zenn/image/fetch/s--VpZayay6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/662f2db0f2.jpeg)
【状況】
Github上で新規に作成したリポジトリに対して、git pushでファイルの送信を試みた際のエラー
【エラー発生までの経緯】
1,Github上のsetting → Developer Settings → Personal access tokensのtokens(classic) → Generate new token
2,権限全て付与した後、tokenをコピーして保存
3,git remote add origin git@github.com:<username>/<repository>.git
を入力後、username,passwordを求められるかと思いきや、上記のエラーが発生
どうやら、SSHでも認証できるらしいが、以前にLinuxでSSHキー認証をした経験がある為、今回はこのままPersonal access tokens(classic)を設定してみる。
![kei](https://res.cloudinary.com/zenn/image/fetch/s--VpZayay6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/662f2db0f2.jpeg)
【解決】
上記のqiitaを元にリモートURLに直接tokenを入力すると、コマンドは
git remote set-url origin https://<username>:<token>@github.com/<username</<repository>.git
になり、git push -u origin main
で無事Github上にファイルが送られた。