1

I have a .ssh/config file configured to connect to different servers with SSH:

###
# Identity files
###
IdentityFile ~/.ssh/id_dsa_home
IdentityFile ~/.ssh/id_dsa_github
IdentityFile ~/.ssh/id_rsa_bitbucket

###
# Global options
###
PasswordAuthentication no
PubkeyAuthentication yes

Host *
  Port 22

Host icarus
  User elitalon
  HostName 192.168.1.1
  Port 54301

Host zeus
  User elitalon
  HostName 192.168.2.1
  Port 54302

Host github
  User git
  HostName github.com

Host bitbucket
  User git
  HostName bitbucket.org

This configuration used to work fine. However, since I upgraded to Mac OS X Mountain Lion SSH behaves differently regarding specific Port values in Host entries:

  1. If I try to connect to zeus SSH always uses port 22, instead of 54301.
  2. If I remove Port 22 and try to connect to a Host without a Port entry, SSH uses the first Port value set (54301 in this example).

After trying different combinations it seems SSH processes all config files but only takes the first value of Port specified, which is an expected behavior according to man page:

For each parameter, the first obtained value will be used

But man page also states that

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.

so I thought that by not specifying any Port value, the default port would change only in those sections where actually have a Port value.

So, how can I setup Host entries to use port 22 except where another value is specified?

Thanks!

2 Answers 2

6

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

Host *
  Port 22

should be moved to the end.

2

Put the "Host *" declaration after all the other host declarations to prevent it from overriding them. But really you should not need this declaration at all since the default is for SSH to use port 22.

You must log in to answer this question.

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