/보안/SSH 'Connection closed by remote host' & 'reset by peer': 5분 진단 및 복구 가이드 (Fail2Ban, MaxStartups)
보안SSH 접속 오류connection reset by peer

SSH 'Connection closed by remote host' & 'reset by peer': 5분 진단 및 복구 가이드 (Fail2Ban, MaxStartups)

SSH 연결 시 발생하는 `ssh_exchange_identification: Connection closed by remote host`와 `kex_exchange_identification: read: Connection reset by peer` 에러를 해결하기 위한 5단계 진단 방법과 복구 가이드를 제공합니다. 다양한 원인별 검사법 및 재발 방지를 제시합니다.

SSH 'Connection closed by remote host' & 'reset by peer': 5분 진단 및 복구 가이드 (Fail2Ban, MaxStartups)

SSH 'Connection closed by remote host' & 'reset by peer': 5분 진단 및 복구 가이드 (Fail2Ban, MaxStartups)

SSH 연결 시 발생하는 ssh_exchange_identification: Connection closed by remote hostkex_exchange_identification: read: Connection reset by peer 에러는 인증 전에 서버 또는 중간 네트워크가 세션을 끊어버렸음을 나타냅니다. 이 가이드에서는 이러한 문제를 해결하기 위한 5단계 진단 방법과 복구 가이드를 제공합니다.

공통 진단 도구: ssh -vvv 로그 확인

먼저, ssh -vvv user@host 명령을 사용하여 verbose 로그를 생성하고 문제의 원인을 파악합니다. 로그에서 중요한 정보는 SSH 연결 과정에서 어디서 멈추었는지 확인하는 것입니다.

  • Connecting to... 직후 reset → 방화벽, hosts.deny, fail2ban 차단 의심
  • Connection established. 직후 배너 전에 closed → MaxStartups 드롭 또는 SYN flood 보호 의심
  • 배너 받은 후 closed → AllowUsers/DenyUsers 미스매치, sshd 비정상 의심

원인 진단 분기 표

증상 / -vvv 로그 위치의심 원인서버 측 검증 명령어복구 명령어
Connecting to... 직후 reset, 특정 IP만① fail2ban banfail2ban-client status sshd, iptables -L -n --line-numbers | grep <IP>fail2ban-client set sshd unbanip <IP>
Connecting to... 직후 closed② TCP Wrappers 거부grep -nE 'ssh|sshd' /etc/hosts.deny /etc/hosts.allowhosts.deny에서 해당 줄 삭제/수정
동시 접속 폭주 시에만 closed③ MaxStartups 초과sshd -T | grep -i maxstartupsMaxStartups 값 상향 후 reload
배너 받은 뒤 closed, 특정 계정만④ Allow/Deny 미스매치sshd -T | grep -iE 'allowusers|denyusers|allowgroups'sshd_config 수정 후 reload
간헐적/재부팅 후 잠깐만 동작⑤ sshd 데몬 비정상systemctl status sshd, journalctl -u sshd -n 50systemctl restart sshd
특정 망에서만 timeout/reset⑥ 방화벽·보안그룹·SYN floodiptables -L -n --line-numbers | grep 22, ufw status numbered포트 22 허용 / 보안그룹 IP 추가

원인 별 진단 및 해결

① fail2ban / sshd 자동 차단으로 내 IP가 ban

Bash
fail2ban-client status sshd
iptables -L -n --line-numbers \| grep <IP>
fail2ban-client set sshd unbanip <IP>

② TCP Wrappers 거부 (hosts.deny)

Bash
grep -nE 'ssh|sshd' /etc/hosts.deny /etc/hosts.allow

③ MaxStartups 초과로 드롭

Bash
sshd -T | grep -i maxstartups
# 예: maxstartups 10:30:100 (10개 넘으면 30% 확률 드롭, 100개에서 전부 거부)

④ AllowUsers / DenyUsers 미스매치

Bash
sshd -T | grep -iE 'allowusers|denyusers|allowgroups'

⑤ sshd 데몬 비정상

Bash
systemctl status sshd
journalctl -u sshd -n 50 --no-pager
sshd -t              # 설정 문법 검사
systemctl restart sshd

⑥ 방화벽 / 보안그룹 차단

Bash
iptables -L -n --line-numbers | grep 22
ufw status numbered

자기 잠금(self-lockout) 복구 — 콘솔 시리얼 접속

SSH가 완전히 막혔다면, AWS와 GCP의 Serial Console을 사용하여 서버에 접속할 수 있습니다.

AWS EC2 Serial Console

  1. EC2 콘솔 → 인스턴스 선택 → Connect → EC2 Serial Console
  2. (사전: 계정 설정에서 Serial Console 활성화 + 로그인 비밀번호 설정)
  3. 접속 후 fail2ban unban / hosts.deny 수정 / 방화벽 해제

GCP Serial Console

  1. Compute Engine → VM 인스턴스 → 연결 → 직렬 콘솔에 연결
  2. 메타데이터 설정 및 비밀번호 로그인 활성화
  3. 차단 규칙 해제

5분 체크리스트

  1. ssh -vvv user@host → 멈추는 지점 확인
  2. Connecting... 직후 reset → fail2ban-client status sshd → unban
  3. closed면 grep -nE 'ssh|sshd' /etc/hosts.deny /etc/hosts.allow
  4. 동시 접속 시에만 → sshd -T | grep -i maxstartups
  5. 특정 계정만 → sshd -T | grep -iE 'allowusers|denyusers|allowgroups'
  6. 간헐적 → journalctl -u sshd -n 50 --no-pagersystemctl restart sshd
  7. 특정 망만 → 방화벽·보안그룹 22번 IP 확인
  8. 다 막혔으면 → 콘솔 시리얼 접속으로 복구

재발 방지 가이드

  • fail2ban ignoreip에 관리 IP 등록, 설정 변경 시 별도 SSH 세션 유지.

참고: 공식 문서

OpenSSH sshd_config 매뉴얼

자주 묻는 질문 (FAQ)

Q1. ping은 되는데 SSH만 끊깁니다. 네트워크 문제인가요? A. 아닙니다. ssh -vvv 로그 확인.

Q2. 평소엔 되는데 동시에 여러 접속을 할 때만 끊깁니다. A. MaxStartups 드롭 가능, sshd -T | grep -i maxstartups.

Q3. 특정 IP에만 차단이 적용되는 이유는? A. fail2ban 등 보안 도구의 자동 차단.

Q4. 방화벽 설정이 잘 되었는데 왜 연결이 안 될까? A. iptables -L -n --line-numbers 또는 ufw status numbered.

Q5. 시리얼 콘솔 접속은 언제 사용해야 하나요? A. SSH 연결이 막혔을 때 가장 유용합니다.

✦ ✦ ✦
편집 검토 · Editorial Review

AI 도구는 자료 조사와 초안 작성의 보조 수단으로 사용될 수 있습니다. Nodelog는 공개 전 내용과 출처를 검토하고, 환경(OS·버전)에 따라 결과가 달라질 수 있는 기술 정보는 공식 문서를 함께 확인하도록 안내합니다. 오류를 발견하시면 이메일로 제보해 주세요 — 확인 후 신속히 정정합니다.

편집 책임 · Nodelog 기술 편집팀·발행 ·

댓글

첫 번째 댓글을 남겨보세요.