気持ちが良いIT技術を学ぶ

Github clone sshキー問題解決

2023年07月18日に更新, By 管理者

Github からクロンする際にsshキーの問題が発生する時の解決方法

% git clone git@github.com:xxxx/xxxx.git xxxxx
Cloning into 'xxxxx'...
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:uNiVztksCxxxxxxxxe8BujQXVUpKZIxxxxxxxxxx.
Please contact your system administrator.
Add correct host key in /Users/xxxx/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/xxxx/.ssh/known_hosts:4
Host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

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

- ed25519のSSHキー生成

既存のrsaキーが使えなく新規でed25519でsshキー生成

% cd ~/.ssh
% ssh-keygen -t ed25519
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/xxxx/.ssh/id_ed25519): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/xxxx/.ssh/id_ed25519
Your public key has been saved in /Users/xxxx/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:ehjFEaaaaP69SHx/6PxxxaaaaxxxxT1Dq7/ASQRydYRE xxxx.local
The key's randomart image is:
+--[ED25519 256]--+
|  ..oE= . o.     |
|   o.o . + oo    |
|  .  . +=... .   |
|   .o +.o...  .  |
|   o....S   o  . |
|  ... .+    .o...|
|   o.oo .  . .o+.|
|   .B  .  .  +o..|
|   .+*     ...=o.|
+----[SHA256]-----+

- 作成した公開鍵確認

% cd ~/.ssh
% ls
id_ed25519      id_ed25519.pub

- 作成した公開鍵をコピー

% cat ~/.ssh/id_ed25519.pub

- GitHubに公開鍵を登録する

  1. GithubのSSH鍵登録画面を開く(https://github.com/settings/keys)
  2. New SSH key
  3. Titleはパソコン名などわかりやすいものにするといい
  4. Keyコピーした公開鍵を貼り付ける
  5. Add SSH Key