Using only part of a pattern in SSH Config Hostname
You can do what you describe in the examples with the match
specification instead of host
. It's another way to specify a host, or a set of hosts.
For example:
Match user u* host t* Hostname %hest.dev User %r
This will match against a user pattern and a target host pattern.
The command line will then be something like ssh u@t
, resulting in this substitution: u@test.dev
.
Here's a snippet from the ssh debug output:
debug2: checking match for 'user u* host t*' host t originally tdebug3: /Users/_/.ssh/config line 2: matched 'user "u"' debug3: /Users/_/.ssh/config line 2: matched 'host "t"' debug2: match found...debug1: Connecting to test.dev port 22.debug1: Connection established....u@test.dev's password:
match
can match against a couple of other things (and there's an option to execute a shell command) but otherwise it's just like host
. The ssh client options that go in there are the same ones (e.g. you can specify and IdentityFile
that will be used with the matching spec)
You can read more in the man page:ssh_config
I think you will have to create separate HostName/User
entries for each possible abbreviation match. You could then use %r
to access separate identity files for each user. This would allow you to skip using user@host
for login at the expense of creating a more complex configuration file.
You might have better luck writing a script or shell alias that unmunges your abbreviations and hands them to ssh
ready to go.