scp 연결 시 "Permission denied" 오류 및 "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" 경고
SSH Tunnel을 통해 연결하려는 경우 scp로 무심코 포트 포워딩 값(예제에서는 10002)을 다음과 같이 사용하면 Permission denied 오류를 경험할 수 있습니다.
C:\temp> scp test.txt tusr@127.0.0.1:10002:~/test.txt
tusr@127.0.0.1's password:
Permission denied, please try again.
tusr@127.0.0.1's password:
Permission denied, please try again.
tusr@127.0.0.1's password:
tusr@127.0.0.1: Permission denied (publickey,password).
lost connection
왜냐하면 scp에서는 "tusr@127.0.0.1:10002:~/test.txt"와 같은 식으로 인자가 전달된 경우 "10002:~/test.txt" 값 전체를 디렉터리로 해석하기 때문에 실제로는 127.0.0.1:22로 연결하는 것과 같습니다. 결국 로컬 PC에 설치된 SSH 서버에 연결하는 것에 불과하므로 운에 따라서 저런 식으로 "Permission denied"가 나거나 전혀 다른 메시지가 보일 수 있습니다.
암튼, scp에서 포트 명시는 "-P" 옵션으로 해야 합니다.
scp -P 10002 test.txt tusr@127.0.0.1:~/test.txt
전형적으로, 해당 오류는 SSH 서버 측의 host key가 변경된 경우에 발생할 수 있습니다. 가령 /etc/ssh 디렉터리에 보관된 키 파일을 재생성하는 등의 사유가 발생하면 SSH 클라이언트 측에서 접속할 때 오류가 발생하게 되는데요,
ERROR: error during connect: Head "http://docker.example.com/_ping": command [ssh -o ConnectTimeout=30 -T -l testusr -- 192.168.100.50 docker system dial-stdio] has exited with exit status 255, make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 ED25519 key sent by the remote host is
SHA256:7B/Kg1o4uXk57uAYG6UnpxS+d8Qr68fctjoUwrOfNcc.
Please contact your system administrator.
Add correct host key in C:\\Users\\TestUsr/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in C:\\Users\\TestUsr/.ssh/known_hosts:9
Host key for 192.168.100.50 has changed and you have requested strict checking.
Host key verification failed.
이럴 때는 오류 메시지에 나오듯이 클라이언트 측의 known_hosts 파일에 있는 해당 호스트의 키를 삭제하고 다시 연결하면 됩니다. 또는, ssh-keygen의 명령어를 통해 신규 키로 갱신하는 것도 가능한데요,
ssh remote host identification has changed [closed]
; https://stackoverflow.com/questions/20840012/ssh-remote-host-identification-has-changed
-R 옵션을 사용하면 ssh-keygen이 알아서 known_hosts 파일의 내용을 교체해 줍니다.
c:\temp> ssh-keygen -R 192.168.100.50
# Host 192.168.100.50 found: line 6
# Host 192.168.100.50 found: line 9
C:\Users\TestUsr/.ssh/known_hosts updated.
Original contents retained as C:\Users\TestUsr/.ssh/known_hosts.old
혹은, (scp의 파일 관리가 좀 정교하지 않은 것 같은데) 어느 순간 위에서와 동일한 오류가 발생할 때가 있습니다.
당황하지 마시고 해당 경로의 파일을 메모장으로 열면,
%USERPROFILE%\.ssh\known_hosts
다음과 같은 식으로 개행이 제대로 안 되어 저장이 되었을 수 있습니다.
127.0.0.1 ecdsa-sha2-nistp256 AAAAE2Vj...[생략]...7g6wVEtv8=[127.0.0.1]:10001 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...[생략]...0ycb3kkOPMEe8=
[127.0.0.1]:10002 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...[생략]...A0j0nwZ+1YBS8=
따라서 그냥 다음과 같이 개행시켜서 저장해 주면 됩니다.
127.0.0.1 ecdsa-sha2-nistp256 AAAAE2Vj...[생략]...7g6wVEtv8=
[127.0.0.1]:10001 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...[생략]...0ycb3kkOPMEe8=
[127.0.0.1]:10002 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...[생략]...A0j0nwZ+1YBS8=
또는 오류가 발생한 [127.0.0.1]:10001의 키 값이 엉뚱하게도 [127.0.0.1]:10002의 항목과 동일하게 설정된 경우도 있었습니다.
127.0.0.1 ecdsa-sha2-nistp256 AAAAE2Vj...[생략]...7g6wVEtv8=
[127.0.0.1]:10001 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...[생략]...0ycb3kkOPMEe8=
[127.0.0.1]:10002 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...[생략]...0ycb3kkOPMEe8=
저럴 때는 그냥 [127.0.0.1]:10001 항목의 값을 삭제하고,
127.0.0.1 ecdsa-sha2-nistp256 AAAAE2Vj...[생략]...7g6wVEtv8=
[127.0.0.1]:10002 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo...[생략]...0ycb3kkOPMEe8=
저장한 후 다시 scp 작업을 하면 새롭게 [127.0.0.1]:10001의 host key 값을 저장하게 만들면 됩니다.
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]