14

I have the following generic host configuration in my .ssh/ssh_config:

Host *
  ConnectTimeout 5
  ServerAliveInterval 5
  ServerAliveCountMax 12

I also have some specific configurations. For example the following alias:

Host work-server-1
  Hostname a.b.c.d

Host work-server-2
  Hostname i.j.k.l

Now, my question: when logging into the host work-server-1, will SSH also use the ConnectTimeout, ServerAliveInterval and ServerAliveCountMax setting as defined in the Host * entry?

1 Answer 1

22

For each directive, the first relevant occurrence in the ssh_config is used.

Quoting man page for ssh_config:

For each parameter, the first obtained value will be used. The configuration files contain sections separated by Host specifications, and that section is only applied for hosts that match one of the patterns given in the specification. ...

Since the first obtained value for each parameter is used, more host-specific declarations should be given near the beginning of the file, and general defaults at the end.


So with the configuration file below:

  • For all hosts, ServerAliveInterval 1 is always used, 4 and 7 are never used, not even for work.
  • ConnectTimeout is 2 for work, for other hosts it's 3.
  • For all hosts, the ServerAliveCountMax is 5, the work-specific value 6 is never used, not even for work.
ServerAliveInterval 1

Host work
  ConnectTimeout 2

Host *
  ConnectTimeout 3
  ServerAliveInterval 4
  ServerAliveCountMax 5

Host work
  ServerAliveCountMax 6
  ServerAliveInterval 7
3
  • 2
    Much obliged Martin.
    – Pritzl
    Commented Jul 4, 2019 at 18:45
  • 2
    You can even use the ssh verbosity flags to see which sets of configurations in which files were loaded, to debug issues
    – Cinderhaze
    Commented Jul 5, 2019 at 14:37
  • 1
    Martin, Martin, he's the man, if he can't do it, then no one can!! Commented Jul 25, 2019 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .