C.W.K.
Stream
Lesson 06 of 14 · published

Two-Factor SSH (TOTP)

~15 min · 2fa, totp, google-authenticator, pam

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

두 번째 factor 추가

Key-only 인증 있어도 도난당한 private key (노트북 도난, agent forwarding 사고) 면 공격자 로그인 가능. Two-factor SSH 가 키와 authenticator 앱의 TOTP 코드 둘 다 요구. 옵션이지만 high-value 서버에 강한 방어.

Flow

서버가 PAM 의 pam_google_authenticator 모듈 사용. User 가 셋업 도구 실행, QR 코드를 authenticator 앱에 스캔, 백업 코드 받음 (저장!). 미래 SSH 에 키 인증 후 서버가 6 자리 verification 코드 물음. ssh-agent 캐싱 있으면 키 부분 자동; 코드만 침.

Code

Linux 서버에 설치·bash
# Install the PAM module
sudo apt install libpam-google-authenticator

# Run the setup tool AS YOUR USER (not root)
google-authenticator
# Answer prompts — accept defaults for time-based, disallow reuse, rate limit on
# Scan the QR code with Authy / Google Authenticator / 1Password
# SAVE THE BACKUP CODES somewhere you can find without your phone
SSH 에 wire·bash
# Edit PAM
sudo nano /etc/pam.d/sshd
# Add at the bottom:
auth required pam_google_authenticator.so

# Edit sshd_config
sudo nano /etc/ssh/sshd_config
# Set:
KbdInteractiveAuthentication yes
AuthenticationMethods publickey,keyboard-interactive

# Validate and restart
sudo sshd -t
sudo systemctl restart sshd

# Test from a NEW session
ssh user@host
# Expected: key auth (silent if agent has key), then TOTP prompt

External links

Exercise

한 서버 (테스트, 유일한 거 X) 에서 위 step 통해 TOTP 셋업. 풀 flow 연습 — 새 세션에서 SSH, verification 코드 prompt 관찰, 입력. 그다음 복구 테스트 — 폰 잃은 척, 백업 코드 사용. 복구 동작하면 2FA 정확히 설정. 락아웃되면 lifeline 세션이 fix.

Progress

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

댓글 0

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

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