3

When I type ssh <server> I want the default behavior to be a password prompt, except for hosts explicitly defined in my .ssh/config file for which I have created public/private key pairs.

My config file currently looks like so:

Host *
    PubkeyAuthentication no

Host <private-server>
    PubkeyAuthentication yes
    IdentityFile <private-server>_key

If I comment out the two Host * lines, then it uses my private key to connect to <private-server>. With the two Host * lines uncommented, however, it requests a password despite the PubkeyAuthentication yes line.

How do I fix this?

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
stevendesu
  • 157
  • 2
  • 15
  • My answer solves your original problem. If a separate answer appears that solves the bonus, which one will you accept? **You have two separate problems, so ask two separate questions.** – Kamil Maciorowski Aug 17 '17 at 19:06
  • I did a rollback to keep the site tidy. Nothing personal. You will find your "bonus" [under this link](https://superuser.com/revisions/1241951/2). Use it to [ask another question](https://superuser.com/questions/ask), really. – Kamil Maciorowski Aug 17 '17 at 19:09
  • I plan on accepting the answer which solves the first problem, I just realized my other issue was also related to an understanding of the ssh config file so I included it (coincidentally simultaneously as your answer). If the bonus points got no response I would have simply left it alone and maybe asked another day – stevendesu Aug 17 '17 at 19:13

1 Answers1

2

From man 5 ssh_config:

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.

Your Host * section is most general. It should be at the very end.

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
  • Just gave this a try and it fixed my issue. I updated the issue just 60 seconds ago with a "bonus points" section, any insight on that as well? – stevendesu Aug 17 '17 at 18:56