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

Key-Only 접근 & 제한

~12 min · authorized_keys, key-restrictions, from, command

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

authorized_keys 가 손님 명단

Password 인증 끄면 각 서버의 ~/.ssh/authorized_keys 가 전체 access policy — 모든 줄이 들어올 수 있는 키. 손님 명단처럼 다뤄 — 모든 항목이 식별 가능, 모든 항목이 감사 가능, revocation 이 한 줄 편집.

키별 제한 — 과소사용 power

개별 항목 앞에 옵션 prepend 해서 키가 할 수 있는 거 제약 — 출처 IP 대역 잠금, specific 명령 강제, port forwarding 비활성, PTY 할당 X. 백업 키 ("이 키 rsync 만 실행"), CI 키 ("이 IP 에서만, 이 스크립트만") 같은 least-privilege 패턴에 유용.

Code

손님 명단 감사·bash
# Look at every entry
cat ~/.ssh/authorized_keys
# Each line:
#   ssh-ed25519 AAAA...abc you_username@macbook-2024
#   ssh-ed25519 AAAA...def you_username@office-mac-studio
#   ssh-ed25519 AAAA...ghi you_username@retired-laptop  ← revoke me

# Show fingerprint for every line — much easier audit
ssh-keygen -l -f ~/.ssh/authorized_keys

# Revoke a single device by comment
sed -i.bak '/retired-laptop/d' ~/.ssh/authorized_keys
키별 제한 (줄 앞에 prepend)·bash
# Restrict to a specific source CIDR
from="192.168.1.0/24" ssh-ed25519 AAAA...xyz lan-only

# Force a single command (key can only ever run this)
command="/usr/local/bin/rsync-receiver",no-pty,no-port-forwarding \
  ssh-ed25519 AAAA...xyz backup-key

# Combine — CI key, IP-restricted, command-locked, no shell
from="203.0.113.0/24",command="/usr/local/bin/deploy.sh",no-pty,no-X11-forwarding,no-agent-forwarding \
  ssh-ed25519 AAAA...xyz ci-deploy-key

External links

Exercise

SSH 하는 어느 서버에서든 ssh-keygen -l -f ~/.ssh/authorized_keys. 쭉 봐. Comment 로 모든 키 식별 가능? 익명 줄이나 stale 장치 이름? 제거 또는 re-comment. 백업 스타일 키엔 command=...,no-pty,no-port-forwarding 추가해 키가 할 수 있는 거 제한.

Progress

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

댓글 0

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

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