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?

  • 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. Use it to ask another question, 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
up vote 1 down vote accepted

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.

  • 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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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