20201026のGitに関する記事は2件です。

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!の対処方法

とある日,git pushしようとするとこんなエラー出た.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for [git.xxxxx.com]:XXXX has changed,
and the key for the corresponding IP address [XX.XX.XX.XXX]:XXXX
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:RGRZ/*********************************************.
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:1
RSA host key for [git.xxxxx.com]:XXXX 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.

エラー原因

~/.ssh/known_hosts に記載されている接続先のサーバ情報と移行後のサーバの情報(今回の場合はIPアドレス)とが異なっているため.

こんな時にエラー出る

サーバの移行後にSFTPクライアントソフトやTerminalで接続をしようとする時.たとえ接続先やSSH認証鍵が合っていてもこのようなエラーが出る.

対処方法

エラーメッセージどおり,~/.ssh/known_hostsの指定された行を削除します.
今回は一行目を削除しました.

どの行を削除すればわからない場合はrm ~/.ssh/known_hostsでファイルごと削除しちゃって大丈夫です.ホストの再登録ができます.

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

良く使うGitコマンド一覧

ローカルブランチを削除する

  • ローカルブランチの確認
$ git branch 
  • 削除コマンド1
$ git branch --delete [ブランチ名]
$ git branch -d [ブランチ名]

(どちらも同じ)
マージ済みのブランチのみ削除ができる
マージされていないブランチを削除しようとすると下記のようなエラーがでます
(error: Cannot delete the branch 'ブランチ名' which you are currently on)
マージされていないブランチを削除したいときは削除コマンド2

  • 削除コマンド2
$ git branch -D [ブランチ名]

どんなローカルブランチも削除できる(マージされていないブランチなど)

git fetch -p
リモートで削除済のブランチも反映される

git diff
変更ファイルを見て何が変わったのかを確認

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む