Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have been putting my ssh identity files inside my ~/.ssh/ folder. I have probably about 30 files in there.

When I connect to servers, i will specify the identity file to use, with something like

ssh -i ~/.ssh/client1-identity client1@10.1.1.10

However, if I do not specify an identity file, and just use something like this:

ssh user123@example.com

I get the error

Too many authentication failures for user123

I understand that is because if no identity file is specified, and ssh can find identity files, then it will try all of them.

I also understand that I can edit the ~/.ssh/config file and specify something like:

Host example.com
PreferredAuthentications keyboard-interactive,password

in order to prevent that connection from trying known identity files.

So, I guess I could move my identity files outside of the ~/.ssh/ directory, or I could specify each host that I want to disable identity-file authentication for in the config file, but is there any way to tell SSH to buy default not search for identity files? Or to specify the ones it will search for?

share|improve this question

migrated from stackoverflow.com Apr 9 '11 at 17:44

This question came from our site for professional and enthusiast programmers.

2  
Re "I understand that is because..." - use ssh -v to find out for sure. –  grawity Apr 9 '11 at 19:19

3 Answers 3

up vote 10 down vote accepted

You can use the IdentitiesOnly=yes option along with IdentityFile (see ssh_config man page). That way, you can specify which file(s) it should look for.

share|improve this answer
    
I must I still have to try to get this working. –  sehe Apr 9 '11 at 17:17
    
An example would be nice –  rubo77 Aug 14 at 5:49

user76528's short answer is correct, but I just had this problem and thought some elaboration would be useful. You might also care about this solution if you've wondered "Why is ssh ignoring my identityfile configuration option"?

Firstly, unlike every other option in ssh_config, ssh does not use the first IdentityFile that it finds. Instead the IdentityFile option adds that file to a list of identities used. You may stack multiple IdentityFile options, and the ssh client will try them all until the server accepts one or rejects the connection.

Second, if you use an ssh-agent, ssh will automatically try to use the keys in the agent, even if you have not specified them with in ssh_config's IdentityFile (or -i) option. This is a common reason you might get the Too many authentication failures for user error. Using the IdentitiesOnly yes option will disable this behavior.

If you ssh as multiple users to multiple systems, I recommend putting IdentitiesOnly yes in your global section of ssh_config, and putting each IdentityFile within the appropriate Host subsections.

share|improve this answer
    
nicely explained, thank you. It's not obvious that that parameter 'IdentitiesOnly' means TakeOnlyWhatIExplicitlySpecifyThenFailoverToPassword. And apparently, the ./ssh/id_rsa key is still listed. –  lImbus Jan 9 at 13:14

You had the answer all along (almost):

Host *
PreferredAuthentications keyboard-interactive,password

Worked for me.

share|improve this answer
1  
The question asked about how to limit which public keys are used. This answer disables public key authentication entirely. –  chrishiestand Jun 12 '12 at 22:11
    
I +1'd because it was the answer I was googling for, thanks @Henry Grebler –  matiu Jul 24 '12 at 6:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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