[Linux] WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! 현상 해결하기

blog post 

 

 

한번씩 SSH로 서버에 연결을 시도하다 보면 다음과 같은 문구가 나타나면서 연결에 실패하는 경우가 발생합니다.

 

[root@Compute0 ~]# ssh root@192.168.0.19
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 ECDSA key sent by the remote host is
SHA256:G2yedUcystIEfv/5nOBSrWQA8RDwN4dHES8/3xNw2mw.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:6
ECDSA host key for 192.168.0.19 has changed and you have requested strict checking.
Host key verification failed.
[root@Compute0 ~]#

 

 

ssh 연결에 사용되는 ecdsa, 혹은 rsa 키 값이 로컬과 원격지의 해시 값이 서로 달라서 발생하는 현상입니다. 아마 원격지의 키 값이 변경되었을 가능성이 큽니다. 

 

 

// localhost(로컬) -> testserver(원격지)

//원격지(192.168.0.19)에서 ecdsa pub키 값
[root@localhost ~]# vim /etc/ssh/ssh_host_ecdsa_key.pub
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...생략...WdxHroNeu8u11Udx3k=

//로컬에서 저장된 원격지의 ecdsa pub 키 값
[root@testserver ~]# vim /root/.ssh/known_hosts
192.168.0.19 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...생략...0yPREZy+LPfLg0dj4=

 

 

이를 해결할 수 있는 두 가지 방법을 소개해 드립니다.

 


 

 

원격지의 값으로 대체하여 해결
 

 

 

첫 번째 방법은 단순하게 원격지의 값을 복사해 와서 사용하는 방법입니다. 

위의 예시에서 원격 연결을 시도하는 로컬의 known_hosts 파일에서 뒤의 해시값만 변경해 봅니다.

 

//로컬에서 저장된 원격지의 ecdsa pub 키 값
[root@localhost ~]# vim /root/.ssh/known_hosts
192.168.0.19 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...생략...0yPREZy+LPfLg0dj4=

 

이후 ssh 서비스를 재시작 후 다시 연결을 시도해 봅니다.

 

[root@localhost ~]# ssh root@192.168.0.19
root@192.168.0.19's password: 

 

연결되는 것을 확인할 수 있습니다.

 

 

 

ssh-keygen 으로 새 키 등록

 

 

더 간단한 방법은 ssh-keygen 명령어를 사용하여 변경된 새로운 키로 로컬 해시 값을 변경하는 것입니다.

 

[root@Compute0 ~]# ssh-keygen -R 192.168.0.19
# Host 192.168.0.19 found: line 6
/root/.ssh/known_hosts updated.
Original contents retained as /root/.ssh/known_hosts.old

[root@Compute0 ~]# ssh root@192.168.0.19
The authenticity of host '192.168.0.19 (192.168.0.19)' can't be established.
ECDSA key fingerprint is SHA256:G2yed...생략.../3xNw2mw.
ECDSA key fingerprint is MD5:13:64:...생략...:87:37:34.
Are you sure you want to continue connecting (yes/no)? 

 

-R 옵션을 사용하면 더 간단하게 원격지 해시 값으로 변경할 수 있습니다.

 

TAGS.

Comments