I have two platforms with many servers I want to connect to via ssh.
I have in resolv.conf
search domain1.net domain2.org
So I only have the machine name to type for ssh.
I want to have an ssh config per domain:
- user admin for every machine of domain1.net
- user root for every machine of domain2.org
How can I achieve that ?
Host, Hostname directives seems to only works with what you type in the ssh command, not what is expanded with DNS suffixes
I believe OpenSSH CAN do canonicalization. Please have a look at the following options in ssh_config man page:
canonical
optionPlease note, this may require newer OpenSSH version than the one you have (I have 7.4p1).
As kasperd said, this is not really possible.
Some workarounds:
I just use some small shell variables to expand
$e
toexample.org
for things I don't access so often. Others are listed in~/.ssh/config
anyway with a short name. You use it like so:With this, you can use the standard
~/.ssh/config
method.Another option: Write a small wrapper script or shell function for ssh that catches the hostname and expands it, something like this:
If you call it with
sshwrapper.sh www
, it will expandwww
towww.example.org
and use this forssh
.backing what @sven said, a tiny bash function can do the same:
Put this somewhere in one of your sourced files, e.g. .profile, and it's always fixing up the name from the search order in /etc/resolv.conf
another approach that could come handy to others utilizes (relatively) new ssh_config features that allow for include files and even the include can be conditional.
I'm just going to share an obfuscated example from my config that tests that if
Then it will include another file that routes some ssh things thru my phone
You should be able to have a ~/.ssh/domain1.ssh & ~/.ssh/domain2.ssh and include those based on a Match test (your test would obviously be customized)