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

Wildcard Hosts

~15 min · wildcards, host-pattern, global-defaults

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

Sharing settings across multiple hosts

Wildcards in Host patterns let you apply settings to a group of hosts at once. * matches any string. ? matches any single character. You can list multiple patterns space-separated.

How matching works

SSH reads ~/.ssh/config top to bottom. For each setting, the first matching Host block wins. So you put specific entries above general ones, and the catch-all Host * at the very bottom.

This means Host * is your global defaults — settings inherited by every host that doesn't override them.

Match vs Host

Beyond Host, OpenSSH also supports Match blocks for conditional matching by user, originalhost, exec result, etc. Useful for advanced setups, overkill for personal fleets. Stick with Host patterns 95% of the time.

Code

Wildcards in action·ssh-config
# Specific host (highest priority)
Host office
    HostName 192.168.1.100
    User you_username

# Pattern match — all Tailscale hostnames
Host ts-*
    User you_username
    # No HostName here — relies on the alias resolving via DNS or another rule

# Pattern match — internal company hosts
Host *.internal.example.com
    User admin
    ProxyJump bastion

# Multiple patterns
Host dev1 dev2 dev3
    User you_username
    IdentityFile ~/.ssh/id_ed25519_dev

# Global catchall — MUST be last
Host *
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile ~/.ssh/id_ed25519
    ServerAliveInterval 60
    ServerAliveCountMax 3

External links

Exercise

Look at your current ~/.ssh/config. Is there a Host * block? Is it at the bottom? If not, move it. Then audit: which directives in your specific Host blocks are duplicated across many hosts? Promote those to Host * so each specific block stays minimal. Test with ssh -G one-host to confirm settings still resolve correctly.

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.