SSH Config Precedence
Let’s consider the below example to understand more about the precedence in ssh options when multiple hosts are defined,
Host nancy HostName 10.21.43.150 Compression no Host jancy HostName 10.2.33.58 PermitLocalCommand no Host trial HostName 10.2.33.57 PermitLocalCommand yes Host *cy !jancy User woot Port 22 Host * User root Port 22 Compression yes
- When a user types ssh nancy, the ssh client applies the options from the first match which is Host nancy. Then it checks for the next matching pattern which is Host *cy !jancy. Then the next matching pattern is Host *, here none of the options are considered as they got over-ridden in the earlier matched patterns. The full list of options are,
Host nancy HostName 10.21.43.150 User woot Port 22 Compression no
- When a user types ssh jancy, the matching patterns are Host jancy and Host *. The options used are,
Host jancy HostName 10.2.33.58 Port 22 User root Compression yes PermitLocalCommand no
- When the user types ssh trial, the matching patterns are Host trial and Host *,
Host trial HostName 10.2.33.57 PermitLocalCommand yes User root Port 22 Compression yes
- For all other remote connections, the ssh client will use Host *cy !jancy and Host *.
How to configure SSH Client in Linux ?
At times we may need to access multiple remote systems with different IP addresses/hostnames, usernames, non-standard-ports with various command-line options. One way is to create a bash alias for each remote connection. But we have an easy and much better solution to this problem. OpenSSH allows to create per-user configuration file to store different SSH options for each remote server. In this article, we will see the basics of SSH Client configuration with some examples.