2

I have a number of entries in ~/.ssh/config:

Host github.com
  Hostname github.com
  User git
  IdentityFile ~/.ssh/github

Host mydomain.com
  User name
  IdentityFile ~/.ssh/id_rsa

Host [email protected]
  Hostname work.com
  User full.name
  IdentityFile ~/.ssh/work_rsa

If none match, the default fallback is id_rsa. But I'd like a different fallback. The following attempt failed, because it catches everything, overriding any previous settings.

Host '*'
  IdentityFile ~/.ssh/fallback

What is the correct way to express "none of the above"?

2
  • 1
    based on unix.stackexchange.com/questions/16571 I was thinking of defining Host '*' at the top Commented Apr 12, 2018 at 15:01
  • 1
    What happens if you just put IdentityFile ~/.ssh/fallback outside of a Host block? Commented Apr 12, 2018 at 15:56

1 Answer 1

0

Move your fallback to the bottom. SSH takes the parameter value from the first matching Host block.

Since Host * will match everything, you want it last. Otherwise, SSH will always pick its IdentityFile.

Host github.com
  Hostname github.com
  User git
  IdentityFile ~/.ssh/github

Host mydomain.com
  User name
  IdentityFile ~/.ssh/id_rsa

Host [email protected]
  Hostname work.com
  User full.name
  IdentityFile ~/.ssh/work_rsa

Host *
  IdentityFile ~/.ssh/fallback

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.