C.W.K.
Stream
Lesson 08 of 12 · published

Known Hosts

~15 min · known-hosts, tofu, host-key, mitm

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

Trust On First Use, 공식화

~/.ssh/known_hosts 가 연결한 모든 서버의 fingerprint 저장. 처음 연결할 때 SSH 가 fingerprint 검증 요청하고 저장. 매 다음 연결 SSH 가 비교 — fingerprint 바뀌면 큰 경고 떠.

무서운 banner — 무슨 뜻

서버의 host key 가 known_hosts 의 거랑 바뀌면 SSH 연결 거부하고 비명 같은 경고:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

두 가능성:

  • Benign — 서버 재설치, OS 다시 깔림, sshd 재구성. Host key 가 재생성됨.
  • Hostile — 누가 연결 가로채는 중 (man in the middle).

어느 건지 알아야 해. 재설치했음 — fine, 옛 fingerprint 를 ssh-keygen -R 로 빼고 새 거 받아. 안 했음 — 멈추고 조사.

known_hosts 미리 채우기

자동화엔 첫 연결 인터랙티브 prompt 원치 않아. ssh-keyscan 이 fingerprint 가져오고 known_hosts 에 append. 또는 StrictHostKeyChecking accept-new 설정 (새 host 자동 수락하지만 변경엔 여전히 경고).

Code

known_hosts 관리·bash
# View entries (each line is hashed by default)
cat ~/.ssh/known_hosts | head

# Remove a specific host (after a legitimate reinstall)
ssh-keygen -R 192.168.1.100
ssh-keygen -R office.local

# Pre-populate without an interactive prompt
ssh-keyscan -H 192.168.1.100 >> ~/.ssh/known_hosts

# Show the server's fingerprint as if you were verifying it manually
ssh-keyscan 192.168.1.100 2>/dev/null | ssh-keygen -lf -

External links

Exercise

자주 SSH 하는 host 하나 골라. ssh-keygen -F that-host 로 known_hosts 항목 찾아. ssh-keyscan that-host 2>/dev/null | ssh-keygen -lf - 돌려서 fingerprint 가 갖고 있는 거랑 일치하는지 검증. 무서운 banner 떴을 때 할 일이 정확히 이거야 — 아무것도 안 깨졌을 때 한 번 연습.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.