🙆
GitHub SSH認証方法
起こった現象
- リモートレポジトリにpushしようとしたら以下のエラーが発生
% git push origin
Enumerating objects: 57, done.
Counting objects: 100% (45/45), done.
Delta compression using up to 8 threads
Compressing objects: 100% (29/29), done.
Writing objects: 100% (29/29), 1.06 MiB | 27.08 MiB/s, done.
Total 29 (delta 9), reused 0 (delta 0), pack-reused 0
error: RPC failed; HTTP 400 curl 22 The requested URL returned error: 400
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
Everything up-to-date
リモートURLをhttps://
で設定している場合エラーが起こりやすいとのことだったので、SSHで設定することにした
% git remote set-url origin git@github.com:nematatu/zenn.git
- そのうえで再度pushしようとしたら以下のエラーが発生
% git push origin
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.
PublicKeyが認証されなかったらしいので再度SSH認証を設置する
手順
SSH Keyがあるか確認
% ls ~/.ssh
→ id_rsa
/ id_ed25519
(秘密鍵)と .pub
(公開鍵)があるか確認。
なければ以下で作成:
ssh-keygen -t ed25519 -C "your_email@example.com"
※your_email@example.com
は GitHub に登録しているメールアドレスにする
PublicKeyをGitHubに登録
.pub
の内容をコピーして、GitHub SSH Keys 設定で登録
- SSHエージェントに登録
% eval "$(ssh-agent -s)"
% ssh-add ~/.ssh/id_ed25519
- 動作確認
% ssh -T git@github.com
以下のようにメッセージが出れば完了
Hi nematatu! You've successfully authenticated, but GitHub does not provide shell access.
おわりに
sshの仕組み全く理解していない
Discussion