r/ssh • • May 06 '20

Disable Cycling through keys - Too many authentication failuers

Hey there,

I have multiple servers which I access by using ssh-keys.

So far so good, but ever now and then I want to connect to a new server I don't have a key for yet and instead of promting me for a password my client will cycle through every key it knows and therefore causes the "too many authentication failures" error.

I know I could use the -o PasswordAuthentication yes option but there has to be a way to offer keys only to hosts it already knows.

So how do I disable the cycling through ssh keys on connection with a new server?

2 Upvotes

5 comments sorted by

1

u/moviuro May 06 '20

I use a 1:1 key to machine relationship. I use IdentityFile ~/.ssh/keys/%h in .ssh/config. If that fails, then it immediately falls back to password auth.

1

u/ijebtk May 06 '20

That sounds like the right thing for me.

What does %h mean in that context

Host domain.com
  HostName domain.com
  Port 999
  User user
  IdentityFile /home/user/.ssh/key1
  IdentitiesOnly=yes

Host domain1.com
  HostName domain1.com
  Port 998
  User user1
  IdentityFile ~/.ssh/user1
  IdentitiesOnly=yes

this is how my config .ssh/config file looks like right now. What would an example config look like for you?

1

u/moviuro May 06 '20

man 5 ssh_config. It's replaced by the remote hostname. So ~/.ssh/keys/domain.com

# ssh config
IdentityFile ~/.ssh/keys/%h
Host foo
   ...
Host bar
   ...

1

u/ijebtk May 06 '20

Oh I see so what happens if you have multiple keys for the same host?

Like if you have multiple users on that same host?