ssh does not read from ssh config

3.1k Views Asked by At

I have an ssh configuration file as follows

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

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

Host para
   User git
   Hostname github.com
   IdentityFile /home/dev/.ssh/para

I do have access for all the github repos and have added public keys

But when I tried to do the following

ssh -T git@default
ssh -T git@para
ssh -T git@work 

It throws an error

ssh: Could not resolve hostname: Name or service not known

I am using ubuntu 20.04 in VMware player

How to fix this issue?

2

There are 2 best solutions below

0
mincom On

You can specify the config file like so:

ssh -F ~/.ssh/config
1
dkf On

You are confusing two concepts.

Each config file definition is a matching pattern so, for example, your first one (default) will match one of the following:

  • ssh -T default
  • ssh -T [email protected] (which will match the first pattern it finds, which is "default", and it will ignore the others)

The first one works because it's matching the declaration. The second one works because the properties that you send to it match the key-value pairs inside of the declaration.

This is why the commands you are using don't work.

For example: ssh -T git@default

This parses out as:

  • User = git
  • Hostname = default

If you go through your list of patterns, none of them match those key-value pairs.

This is also why you're getting Could not resolve hostname: Name or service not known - because the Hostname "default" does not exist (so it can't be resolved).

Just reference them by name... so:

ssh -T default
ssh -T work
ssh -T para

Per the docs:

Host: Restricts the following declarations (up to the next Host or Match keyword) to be only for those hosts that match one of the patterns given AFTER the keyword. ... The host is USUALLY the hostname argument given on the command line (see the CanonicalizeHostname keyword for exceptions).

Docs: https://man.openbsd.org/ssh_config#Host