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

Key Rotation

~15 min · rotation, expiration, ca-issued

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

Panic 아니라 calendar 로 키 rotate

SSH 키도 password 처럼 나이 들어. 분기별 rotation 이 개인 fleet 에 옳은 cadence — 발견 안 된 침해의 폭발 반경 제한할 만큼 잦고, 일상 ops 노가다 안 될 만큼 드뭄. 한 번 해보면 절차가 기계적.

Fleet 전반 rotation 절차

  1. 각 장치에서 fresh comment 와 새 키 생성.
  2. 모든 서버의 authorized_keys 에 새 public key 를 옛 거 옆에 배포.
  3. 각 장치의 ~/.ssh/config 새 키 사용으로 업데이트.
  4. 각 장치에서 exhaustively 테스트.
  5. 모든 서버에서 옛 public key 제거.
  6. 각 장치에서 옛 private key 삭제.

Step 2 와 5 가 병렬화 가능 부분 — 거기가 fleet helper (Track 7) 자기 값 하는 곳.

Code

수동 rotation step·bash
# 1. Generate new key, fresh comment
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_2026q4 \
    -C "$(whoami)@$(hostname -s)-2026q4"

# 2. Push new public key to every server (alongside old one)
for host in $(cat ~/.fleet/all.txt); do
    ssh-copy-id -i ~/.ssh/id_ed25519_2026q4.pub "$host"
done

# 3. Update ~/.ssh/config to point at the new key
# Host *
#     IdentityFile ~/.ssh/id_ed25519_2026q4

# 4. Test exhaustively
for host in $(cat ~/.fleet/all.txt); do
    ssh -i ~/.ssh/id_ed25519_2026q4 \
        -o IdentitiesOnly=yes \
        -o ConnectTimeout=5 \
        "$host" 'echo OK' || echo "$host FAILED"
done

# 5. Remove old public key from every server
OLD_FP=$(ssh-keygen -lf ~/.ssh/id_ed25519_OLD.pub | awk '{print $2}')
for host in $(cat ~/.fleet/all.txt); do
    ssh "$host" "
        cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak.\$(date +%s)
        ssh-keygen -f ~/.ssh/authorized_keys -R '$OLD_FP' 2>/dev/null || \
            sed -i.bak '/$OLD_COMMENT/d' ~/.ssh/authorized_keys
    "
done

# 6. Finally, delete old private key locally
rm ~/.ssh/id_ed25519_OLD ~/.ssh/id_ed25519_OLD.pub

External links

Exercise

분기별 rotation 계획 (반드시 실행 X). 적기 — 오늘 어느 장치가 키 가짐, 각 키가 어느 서버에 authorize 됨, rotation 스크립트 어디서 실행. 한 번 매핑하는 행위가 손으로 rotation 가능한지 또는 SSH 인증서 먼저 셋업해야 하는지 알려줌. 5+ 장치 9+ 서버엔 인증서 거의 항상 이김.

Progress

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

댓글 0

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

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