About multiple hosts with same hostname

Jim Knoble jmknoble at pobox.com
Wed Apr 1 10:45:53 EST 2009


On 2009-03-31 15:57, Christian Iversen wrote:

: An even better solution, now that I think of it, could be to define a 
: shell function named "ssh" that resolves the host part into a FQDN, 
: based on the search domain for the host, checked against a whitelist of 
: valid customer site named.
: 
: That way, only FQDNs would ever be stored. These are unique by 
: definition, so that should solve it pretty cleanly.

Writing wrapper functions or scripts for ssh(1) (and scp(1), etc.) is
somewhat difficult, unless the wrapper script reproduces the same
getopt() syntax that ssh(1) uses.  Even so, options or arguents that
contain whitespace or shell metacharacters often don't work so well.

An alternative approach would be to pre-build a ~/.ssh/config file that
contains usable hostname aliases for each customer's "fw0" host.  For
example:

    Host fw0.customer1.example.net fw0.cust1 cust1-fw0
        HostName fw0.customer1.example.net

    Host fw0.customer2.example.net fw0.cust2 cust2-fw0
        HostName fw0.customer2.example.net

    # [and so on...]

Thus, both 'ssh cust1-fw0' and 'ssh fw0.cust1' both get to the same fw0
host in customer1's domain.

This could be done by a script, optionally assembling ~/.ssh/config from
a top portion, a repeated template filled in for each customer, and a
bottom portion.  If you wanted to get fancy, you could either
generate ~/.ssh/config on a daily basis or when the list of customer
domains changes.

This doesn't require any wrapper function or shell script, it still
uses DNS to resolve the hostname, and it works for ssh(1), scp(1),
sftp(1), rsync(1), etc.

Judicious use of bash or zsh completion could probably be used along
with this to make it even easier, if cust1, cust2, etc. are sufficiently
different.

Good luck to the original poster.

-- 
jim knoble  |  jmknoble at pobox.com  |  http://www.pobox.com/~jmknoble/
(GnuPG key ID: C6F31FFA  >>>>>>  http://www.pobox.com/~jmknoble/keys/ )
(GnuPG fingerprint: 99D8:1D89:8C66:08B5:5C34::5527:A543:8C33:C6F3:1FFA)


More information about the openssh-unix-dev mailing list