Ssh exchange identification: Connection closed by remote host

SSH 접속 불가
Connection closed by foreign host
외부 호스트에 의해 접속이 종료되었습니다.

1 문제 상황

아래와 같은 메시지가 나오면서 SSH 접속이 되지 않는다.

Looking up host 'example.com'...
Host 'example.com' resolved to 111.222.33.44.
Connecting to 111.222.33.44:22...
Connection established.
Escape character is '^@]'.

Connection closed by foreign host.

다른 서버에서 접속한 후 거기서 시도해 봐도 되지 않는다.

[root@localhost ~]# ssh example.com
ssh_exchange_identification: Connection closed by remote host
[root@localhost ~]# ssh 111.222.33.44
ssh_exchange_identification: Connection closed by remote host

파일질라로 SFTP 접속을 시도해보니 역시 되지 않는다.

상태:	example.com에 연결...
응답:	fzSftp started
명령:	open "root@example.com" 22
오류:	Server unexpectedly closed network connection
오류:	서버에 연결하지 못함

2 포트 점검

포트는 열려 있다. 따라서 sshd도 구동중일 것이다. 그리고 웹페이지 접속도 잘 되고 있으므로 OS hang이라고도 볼 수 없다...

C:\Users\jmnote>tcping example.com 22

Probing 111.222.33.44:22/tcp - Port is open - time=38.762ms
Probing 111.222.33.44:22/tcp - Port is open - time=6.646ms
Probing 111.222.33.44:22/tcp - Port is open - time=9.805ms
Probing 111.222.33.44:22/tcp - Port is open - time=8.058ms

Ping statistics for 111.222.33.44:22
     4 probes sent.
     4 successful, 0 failed.
Approximate trip times in milli-seconds:
     Minimum = 6.646ms, Maximum = 38.762ms, Average = 15.818ms

3 사례 1: 재부팅(원인불명)

원인은 모르겠지만 재부팅으로 해결되었다...

  • 서버에 VNC 접속 설정이 되어 있다면 VNC Viewer로 접속해보면 좋은데, 설정이 되지 않은 서버이다.
  • 서버원격관리 메뉴에서 '종료'를 실행했는데 5분이 지나도 꺼지지 않는다.
  • 서버원격관리 메뉴에서 '강제종료'를 실행하니 곧 꺼졌다.
  • 서버원격관리 메뉴에서 '시작'를 실행했고 부팅 후에는 모든 것이 정상이다. (SSH 접속, 웹서비스 다 잘 된다.)
  • last로 최근 접속 기록을 살펴보니 외부 침입은 없었던 것 같다.
  • 석연치 않지만 결론: SSH 접속불가(메시지: Connection closed by foreign host) -- 원인은 불명. -- 재부팅으로 해결.

4 사례 2:

평소 자주 접속하는 PC에서 접속하니 잘 된다...

  • SSH 보안 강화 때문이었다.
[root@jmnote ~]# cat /etc/hosts.deny | grep -v ^#
sshd: ALL

[root@jmnote ~]# cat /etc/hosts.allow | grep -v ^#
sshd: 135.79.246.80, 123.456.
→ 모든 IP에서의 ssh 접속을 제한. (단, 지정한 IP대역[1]은 제외)
  • hosts.allow 에 IP를 추가해주니 sshd 재시작 없이 바로 접속된다.

5 같이 보기

6 주석

  1. 135.79.246.80과 123.456.x.x
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}