4
2

More than 1 year has passed since last update.

githubにSSH接続ができなくなったら

Last updated at Posted at 2022-05-12

エラー内容

githubにpushしようとした時に下記のエラーが出てpushができなくなった。

ERROR: You're using an RSA key with SHA-1, which is no longer allowed. Please use a newer client or a different key type.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.

fatal: Could not read from remote repository.

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

どうやら、SHA-1を使用したRSA署名というものが使えなくなっている様子。

新しい公開キーの生成

下記のコマンドで生成した公開キーならssh接続ができるようになるみたい。

$ssh-keygen -t ecdsa -b 521 -C "hoge@example.com"

この時のメールアドレスはgithubに登録してあるメールアドレスを入力。
3回何か聞かれる。

  • 保存するファイル名
  • パスワード
  • 再度パスワード

特に設定しなくても大丈夫なので3回EnterKey連打でOK。
今回はファイル名だけ「hoge」と入力。

githubに公開キーを登録

公開キーの中身を確認する。

$cat ~/.ssh/hoge.pub
ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBAEoOapWnd/
tZLoqDt6SnNVNargRHLl6nLYEeUyTuXaiw3s3CRp/qOXH5+Mb/qIY9OWuSAtyAqQPTHJXSvC2I4v6bACujP
3UHcdhA2aLy9gxjgWyrHIYErPmiq/78aBxkvTaIB5i3efGTtDmdGb6eR82eKXB/88v1mwKBkVc1/Qn2X/xd
g== hoge@example.com

生成した公開キーのメールアドレス以外をコピーして、
https://github.com/settings/keys
の 「New SSH key」 ボタンから登録してあげる。
image.png
Titleの欄には「自宅用PC」等任意の名前を入力してあげる。
Keyの欄に先ほどコピーした公開キーを張り付けて「Add SSH key」ボタンをクリックしてOK。

SSH接続確認

configファイルに下記を記述する。

~/.ssh/config
Host github github.com
  HostName github.com
  IdentityFile ~/.ssh/hoge
  User git

下記のコマンドを実行する。

ssh -T github
Hi githubのユーザー名! You've successfully authenticated, but GitHub does not provide shell access.

と出たらSSH接続成功。

githubにpushしてみる

D:\test> git push
Counting objects: 2, done.
~
   ed7a30d..14a6f16  master -> master

できた。

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