0

My current .ssh/config file has below config.

Host *
    FingerprintHash sha256
    StrictHostKeyChecking yes
    PasswordAuthentication no
    GSSApiAuthentication no
    KbdInteractiveAuthentication no
    CheckHostIP yes
    ControlMaster auto
    ControlPath ~/.ssh/master-%r@%h:%p
    Port 28282

And I want to add another rule applies only for one host ip(1.2.3.4).

So, I added below rules in .ssh/config file.

Host 1.2.3.4
    Hostname 1.2.3.4
    Port 22

But the first wider rule keeps affecting to 1.2.3.4 rule.
I want to ssh to 1.2.3.4 only with default settings like login with password(not affected by * rules).

When I run ssh -v root@1.2.3.4, it shows below message(looks * rule is applied). And keep trying through port 28282.

debug1: /home/ryan/.ssh/config line 23: Applying options for *
debug1: /home/ryan/.ssh/config line 74: Applying options for 1.2.3.4
..
debug1: Connecting to 1.2.3.4 [1.2.3.4] port 28282.
debug1: connect to address 1.2.3.4 port 28282: Connection refused

What do I need to change to login with password and port 22 to 1.2.3.4?

Thanks in advance.

1

1 Answer 1

3

I would imagine you have the groups in the wrong order. It's not at all clear from the documentation (man ssh_config) but, "For each parameter, the first obtained value will be used.", so the more general match needs to be further down the configuration file.

Put them in this order:

Host 1.2.3.4
    Port 22

Host *
    FingerprintHash sha256
    StrictHostKeyChecking yes
    PasswordAuthentication no
    GSSApiAuthentication no
    KbdInteractiveAuthentication no
    CheckHostIP yes
    ControlMaster auto
    ControlPath ~/.ssh/master-%r@%h:%p
    Port 28282

Or else move the Host * settings outside of the block and make them global. You can then override these with your Host 1.2.3.4 block, etc.

However, it might make more sense to enumerate the set of hosts with the special case, either by name or as patterns. Then the default action of using port 22 will continue to work for all systems everywhere.

1
  • Thanks for your explain. But after testing, for using password only for 1.2.3.4, I need to put 'PasswordAuthentication yes' under 'Host 1.2.3.4' section. Hope this help to someone.
    – Hardguy
    Jun 26 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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