Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
  Port 54301

Host zeus
  User elitalon
  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?


share|improve this question

2 Answers 2

up vote 4 down vote accepted

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.


Host *
  Port 22

should be moved to the end.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.