Instead of any free-floating parameters in my .ssh/config, I prefer encapsulation in Host
blocks so that parameters can be overridden without a Match
block. This way is still only 3-6 lines except for the annotating comments, and none of the configuration leaks to other hosts. Any generic changes to the default parameter values can go in a Host *
at the bottom, in line with the manpage suggestion:
Since the first obtained value for each parameter is used, more host-specific declarations should be given near the beginning of the file, and general defaults at the end.
Otherwise, you discover that you've set everything to CanonicalizeHostname yes
, and you have to refactor when that turns out be a hindrance for some other Host
.
# Wildcard matches host1, host2, etc.
# Alternatively, `host*` to match multiple suffix characters. You can also
# add additional patterns like `files?` or `app` to append the domain to them.
Host host?
# Token replacement with `%h`, so host1, host2, etc. map correctly
HostName %h.example.com
CanonicalizeHostname yes
# This is optional, but you can have a separate user for host1 and friends
# than you do for the rest of `*.mydomain.com` if that's helpful.
User specialusername
# If you ONLY use host1 and friends when you visit `*.mydomain.com`, you can
# just have the `User` parameter above and drop this block entirely.
Host *.example.com
User myusername
The previous answers to this question don't combine things in quite the same way I do, although Max's post comes close. Max is only missing the %h
token, which is pretty useful for combining rules on big systems.
There's tab-completion from ssh h
tab to ssh host
, and you can type 1enter to visit host1
.