0

I have 2 sets of hosts who I want to use settings from 2 seperate wildcard hosts.

I also have a huge number of hosts so need help on which style is best for this scenario. The hosts are mostly in the format of x1 x2 x3...

My attempts:

1:

host one
  user cat

host two hostname 2

host three hostname 3

host one two three user apple identityFile ~/.ssh/id_rsa

host x1 hostname 7

host y2 hostname 8

host z3 hostname 9

host x1 y2 z3 user duck identityFile ~/.ssh/quack

Omitting the hosts only using the wild card hosts but they apply to the hosts.

2:

 host x* y* z*
  user duck
  identityFile ~/.ssh/

for hosts one two three

host * user apple IdentityFile ~/.ssh/quack

Are these methods correct and Any suggestions for a better methods?

Please critique.

Nickotine
  • 467

1 Answers1

1

Using as reference this answer you can use wildcards in ssh client config file.

So config should be feasible but I will suggest to list explicitly as much as possible hosts

 host x* y* z*
  user duck
  identityFile ~/.ssh/

for hosts one two three

host one 2 3 user apple IdentityFile ~/.ssh/quack

Setting record like

host * 
user apple
IdentityFile ~/.ssh/quack

can sometime bring unexpected errors (because of the host wildcard interpretation)

Romeo Ninov
  • 17,484
  • do you have any other tricks to group hosts together? Or is listing each host at good as it gets? – Nickotine Nov 03 '23 at 12:28
  • @Nickotine, list with all hosts is OK, but can be challenge to maintain it. Try to aggregate w/o go to extreme. – Romeo Ninov Nov 03 '23 at 12:49
  • could you pass an array or a variables with many hosts in it? – Nickotine Nov 03 '23 at 12:59
  • @Nickotine, I do not thing so. and IMHO do not over-complicate simple things :) – Romeo Ninov Nov 03 '23 at 13:27
  • 1
    I'm just saying what if you had 100 servers... that took wildcard values but had some unique ones. 50 might take wildcard values from 1 host and the rest from another host, their names might be in a format where you coulfn't catch them with regex – Nickotine Nov 03 '23 at 14:23
  • @Nickotine, if they can't be "defined" with regex just describe them one by one (host one 2 3). At the end this is one time task :) – Romeo Ninov Nov 03 '23 at 15:32
  • err even if it's 1000 or even 100 hosts? – Nickotine Nov 03 '23 at 17:05
  • @Nickotine, if they are 1000 hosts wildcard is good solution, will speedup of host identification from ssh config. But to have 1000 hosts with wide diversity of identities, usernames, etc tell me there is something wrong with this organization... – Romeo Ninov Nov 03 '23 at 17:09
  • I can't disagree with that hahah yes the companies I've worked with all have similarly named hosts. I was just speaking in hypotheticals, thank you. – Nickotine Nov 03 '23 at 21:24