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

Public key 설치

~15 min · ssh-copy-id, authorized-keys, permissions

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

Public key 를 서버에 올리기

키 기반 인증이 동작하려면 public key 가 서버의 ~/.ssh/authorized_keys 파일 (한 줄에 키 하나) 에 있어야 해. 세 가지 방법 — easy, manual, 직접 편집.

쉬운 방법 — ssh-copy-id

ssh-copy-id 있으면 (Linux 예, macOS 기본 X 지만 brew install ssh-copy-id) 다 처리해 — password 로 연결, 필요하면 ~/.ssh/ 만들고, 키 append, 권한 정확히 설정. 한 명령, 끝.

Manual 방법

ssh-copy-id 없으면 디렉토리 만들고 append 하는 SSH 세션으로 public key pipe. 또는 손으로 서버의 authorized_keys 에 paste.

권한이 중요해 — 조용히

SSH 는 권한이 너무 느슨하면 authorized_keys (또는 .ssh 디렉토리) 사용 거부. 실패 모드가 조용해 — 인증이 그냥 password 로 fallback, 왜인지 안 알려줌. 키 인증이 미스터리하게 안 될 때 권한 먼저 확인.

Code

Public key 설치 세 방법·bash
# Easy — ssh-copy-id (install with `brew install ssh-copy-id` on macOS)
ssh-copy-id you_username@192.168.1.100
ssh-copy-id -i ~/.ssh/id_ed25519.pub you_username@192.168.1.100

# Manual — pipe through ssh
cat ~/.ssh/id_ed25519.pub | ssh you_username@192.168.1.100 \
  'mkdir -p ~/.ssh && chmod 700 ~/.ssh && \
   cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys'

# Direct — copy your key, ssh in, paste it into authorized_keys
cat ~/.ssh/id_ed25519.pub   # copy the output
ssh you_username@192.168.1.100
# Then on the server:
echo 'PASTE_THE_KEY_HERE' >> ~/.ssh/authorized_keys
권한 고치기·bash
# On the server side
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
# Home directory itself must not be group-writable
chmod o-w,g-w ~

# Test from a fresh terminal
ssh you_username@192.168.1.100

External links

Exercise

LAN 에서 타겟 머신 골라. 세 방법 중 아무거나로 public key 설치. 새 터미널에서 테스트 — ssh you_username@target 이 password prompt 없이 들어가야 함. 보너스 — 일부러 깨봐. 타겟에서 chmod 644 ~/.ssh/authorized_keys. 다시 SSH 시도, password fallback 보고 (-v 로 SSH 가 키 거부하는 거 봐), chmod 600 으로 fix.

Progress

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

댓글 0

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

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