Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

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 값을 저장하게 만들면 됩니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 10/15/2025]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 121  122  123  124  125  126  127  [128]  129  130  131  132  133  134  135  ...
NoWriterDateCnt.TitleFile(s)
10827정성태7/8/201536662개발 환경 구성: 273. Visual Studio 2015에서 Github와 연동하는 방법 [3]
10826정성태7/8/201528407오류 유형: 301. The trust relationship between this workstation and the primary domain failed. - 두 번째 이야기
10825정성태7/8/201525312개발 환경 구성: 272. Visual Studio IDE 설치 없이 Visual Studio SDK 설치하는 방법
10824정성태7/7/201531472개발 환경 구성: 271. Team Foundation Server 2015 설치 방법 [1]
10823정성태7/7/201533487오류 유형: 300. SqlException (0x80131904): Unable to open the physical file
10822정성태7/7/201531456오류 유형: 299. The 'Visual C++ Project System Package' package did not load correctly.
10821정성태7/7/201524812오류 유형: 298. Unable to start debugging on the web server. IIS does not list a web site that matches the launched URL.
10820정성태7/7/201530319오류 유형: 297. HTTP Error 503. The service is unavailable. - 두 번째
10819정성태7/2/201533139오류 유형: 296. SQL Server Express 시작 오류 - error code 3417
10818정성태7/1/201532792오류 유형: 295. HTTP Error 503. The service is unavailable. [1]
10817정성태6/29/201538187.NET Framework: 523. C# 람다(Lambda)에서 변수 캡처 방식 [3]
10816정성태6/25/201532386.NET Framework: 522. 닷넷의 어셈블리 서명 데이터 확인 방법파일 다운로드1
10815정성태6/23/201531187Graphics: 1. 자네 나와 함께... UNITY 하지 않겠는가! [4]
10814정성태6/22/201529046.NET Framework: 521. Roslyn을 이용해 C# 문법 변형하기 (2) [5]
10813정성태6/21/201529590.NET Framework: 520. Roslyn을 이용해 C# 문법 변형하기 (1)
10812정성태6/20/201530437.NET Framework: 519. C# 6.0 오픈 소스 컴파일러 Roslyn - 빌드 및 테스트 방법 [1]
10811정성태6/20/201527340오류 유형: 294. OpenAuth 사용 시 System.Data.SqlClient.SqlException 예외가 Output 창에 출력되는 문제
10810정성태6/18/201527251개발 환경 구성: 270. Visual Studio에서 github 오픈 소스를 fork해서 테스트하는 방법 [1]
10809정성태6/18/201524990.NET Framework: 518. AllowPartiallyTrustedCallers 특성이 적용된 GAC 어셈블리에서 DynamicMethod의 calli 명령어 사용파일 다운로드1
10808정성태6/17/201526166.NET Framework: 517. calli IL 호출이 DllImport 호출보다 빠를까요? [1]파일 다운로드1
10807정성태6/16/201528439.NET Framework: 516. Microsoft.AspNet.Membership.OpenAuth 사용 시 "Local Database Runtime error occurred" 오류
10806정성태6/16/201544896.NET Framework: 515. OpenAuth.VerifyAuthentication 호출 시 The remote server returned an error: (400) Bad Request
10805정성태6/15/201527557Java: 17. 자바의 재미있는 상수 처리 방식
10804정성태6/10/201527702.NET Framework: 514. .NET CLR2 보안 모델에서의 APTCA 역할 (2)파일 다운로드1
10803정성태6/2/201530076.NET Framework: 513. UWP(Universal Windows Platform) 응용 프로그램의 새로운 라이브러리 버전 관리 해법 [2]
10802정성태6/2/201528370개발 환경 구성: 269. 마이크로소프트 온라인 강좌 소개 - Azure VPN 구성 방법 [1]
... 121  122  123  124  125  126  127  [128]  129  130  131  132  133  134  135  ...