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

Host Aliases

~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 and after

Without an SSH config alias, you type the full incantation every time:

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

With an alias, you type:

ssh office

Same effect. Every connection detail lives in ~/.ssh/config once. This isn't just convenience — it eliminates typos, ensures consistent settings, and makes scripts portable. scp file.txt office:/dest/, rsync -avz ./code/ office:/code/, ssh-copy-id office all just work because every SSH-based tool reads ~/.ssh/config.

The four lines you'll write 99% of the time

Most host blocks need just these four directives:

  • Host alias — the name you'll type
  • HostName ip-or-fqdn — the actual address
  • User username — the remote username
  • IdentityFile ~/.ssh/... — which key to use (often inherited from Host *)

Code

A small fleet of aliases·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
Use the aliases everywhere·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

List every machine you SSH into in any given month. For each, add an alias to ~/.ssh/config with HostName + User. From now on, never type a raw IP again — always use aliases. If a script in your repos has hardcoded IPs, that's a refactor candidate.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.