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

Host Alias

~15 min · ssh-alias, hostname, user, port

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

Before & after

SSH config alias 없으면 매번 풀 주문 외워야 해:

ssh you_username@192.168.1.10 -p 2222 -i ~/.ssh/id_ed25519_office

Alias 있으면:

ssh office

같은 효과. 모든 연결 디테일이 ~/.ssh/config 에 한 번 살아. 편의 그 이상 — 오타 제거, 일관 설정 보장, 스크립트 portable. scp file.txt office:/dest/, rsync -avz ./code/ office:/code/, ssh-copy-id office 다 동작 — 모든 SSH 기반 도구가 ~/.ssh/config 읽으니까.

99% 시간 쓰는 4 줄

대부분 host block 은 이 네 directive 면 충분:

  • Host alias — 칠 이름
  • HostName ip-or-fqdn — 실제 주소
  • User username — 원격 username
  • IdentityFile ~/.ssh/... — 어느 키 쓸지 (보통 Host * 에서 상속)

Code

작은 fleet alias·ssh-config
# Workstations
Host office
    HostName 192.168.1.10
    User you_username

Host server
    HostName 192.168.1.11
    User you_username

Host music
    HostName 192.168.1.12
    User you_username

# Laptop
Host macbook
    HostName 192.168.1.20
    User you_username

# An external bastion on a non-default port
Host bastion
    HostName bastion.example.com
    User you_username
    Port 2222
Alias 어디서나 사용·bash
# Interactive
ssh office

# One-shot command
ssh office 'uptime'

# Copy files
scp ./report.md office:/tmp/

# Sync project
rsync -avz --delete ./project/ office:/home/you_username/project/

# Push your public key for the first time
ssh-copy-id macbook

External links

Exercise

지난 한 달 동안 SSH 한 모든 머신 나열. 각각에 ~/.ssh/config 에 alias 추가 — HostName + User. 이제부턴 raw IP 절대 안 침 — 항상 alias. Repo 의 스크립트에 hardcode IP 있으면 refactor 후보.

Progress

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

댓글 0

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

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