I make use of an .ssh/config file to set my username appropriately based on a given portion of a subdomain, e.g.
Host *widgetshop.com*
User foobar
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h:%p
Host *
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h:%p
This works if I write:
ssh foo.widgetshop.com
but does not work if I were to write:
ssh foo
which upon search path resolution becomes the same fqdn.
Anyone have a way to expand shortnames before calling ssh, or an alternative approach?
As of OpenSSH 6.5, you can do this with the
CanonicalizeHostname
option in ssh_config. Here's an example that should do what you want:Perhaps you can use the
host
command:Put that into a shell script (replace "foo" with "$1") and exec ssh.
The ssh_config manpage answers this:
In other words, it doesn't work because it doesn't work that way.
please see my "alternative approach")