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

SSH Config

~10 min · ssh, config, tunnel

Level 0창 구경꾼
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

~/.ssh/config — 원격 주소록

config 없으면 매 ssh 마다 호스트 / 사용자 / 포트 / 키 경로 전부 입력. ~/.ssh/configssh -i ~/.ssh/work_id -p 2222 alice@server.example.comssh work 로 줄여줘. scp, rsync, 그리고 ssh 를 안에서 쓰는 모든 도구도 같이 단축돼.

모양

Host work
  HostName server.example.com
  User alice
  Port 2222
  IdentityFile ~/.ssh/work_id_ed25519
  IdentitiesOnly yes

Host *.internal
  User root
  ProxyJump bastion.internal

지시문은 들여쓰기. 패턴 (*.internal, 10.0.*) 은 alias 매칭. 순서 중요 — 충돌 시 먼저 나오는 블록 우선.

흔한 지시문

  • IdentityFile ~/.ssh/foo — 사용할 키.
  • IdentitiesOnly yes — 그 키 한 개만 시도 (agent 가 모든 키 스팸 시도해서 서버가 잠그는 사고 방지).
  • ProxyJump bastion — jump host 경유.
  • ForwardAgent yes — 로컬 agent 포워딩 (조심).
  • LocalForward 5900 localhost:5900 — 접속 시 자동 터널.
  • ControlMaster auto, ControlPath ~/.ssh/cm-%r@%h:%p — 여러 command 가 한 connection 공유. rsync 반복 등에서 엄청 빨라짐.

권한 중요

~/.ssh 는 700, 안의 파일은 600. 헐거우면 ssh 가 키 사용 거부 ('Permissions are too open'). dotfile clone 직후 chmod 700 ~/.ssh; chmod 600 ~/.ssh/* 한 번이 한 시간 디버깅을 막아.

빠른 테스트

ssh -T host 가 shell 안 열고 인증만 시도. ssh -v host 는 클라이언트의 모든 단계 출력. 디버깅에 유용.

Code

SSH config 시작·bash
mkdir -p ~/.ssh && chmod 700 ~/.ssh
cat > ~/.ssh/config <<'EOF'
Host *
  ServerAliveInterval 60
  ServerAliveCountMax 3
  ControlMaster auto
  ControlPath ~/.ssh/cm-%r@%h:%p
  ControlPersist 1h

Host server
  HostName 192.168.1.10
  User you_username
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes
EOF
chmod 600 ~/.ssh/config

External links

Exercise

~/.ssh/config 열거나 생성. Host * 블록에 ServerAliveInterval 60 추가. 특정 Host 하나 더. chmod 700 ~/.ssh; chmod 600 ~/.ssh/config. ssh -T <host> 로 테스트.

Progress

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

댓글 0

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

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