Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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@

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


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:

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 Apr 9 '11 at 17:44

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

Re "I understand that is because..." - use ssh -v to find out for sure. – grawity Apr 9 '11 at 19:19
up vote 27 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
An example would be nice – rubo77 Aug 14 '14 at 5:49

I generally do it like so:

$ ssh -o IdentitiesOnly=yes -F /dev/null -i ~/path/to/some_id_rsa

The options are as follows:

  • -o IdentitiesOnly=yes - tells SSH to only use keys that are provided via the CLI and none from the $HOME/.ssh or via ssh-agent
  • -F /dev/null - disables the use of $HOME/.ssh/config
  • -i ~/path/to/some_id_rsa - the key that you explicitly want to use for the connection


$ ssh -v -o IdentitiesOnly=yes -F /dev/null -i ~/my_id_rsa
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /dev/null
debug1: Connecting to [] port 22.
debug1: Connection established.
debug1: identity file /Users/sammingolelli/my_id_rsa type 1
debug1: identity file /Users/sammingolelli/my_id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA f5:60:30:71:8c:a3:da:a3:fe:b1:6d:0b:20:87:23:e1
debug1: Host 'someserver' is known and matches the RSA host key.
debug1: Found key in /Users/sammingolelli/.ssh/known_hosts:103
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/sammingolelli/my_id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to ([]:22).
debug1: channel 0: new [client-session]
debug1: Requesting
debug1: Entering interactive session.
Last login: Tue Dec  8 19:03:24 2015 from

Notice in the above output that ssh has only identified the my_id_rsa private key via the CLI and that it uses it to connect to someserver.

Specifically these sections:

debug1: identity file /Users/sammingolelli/my_id_rsa type 1
debug1: identity file /Users/sammingolelli/my_id_rsa-cert type -1


debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/sammingolelli/my_id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
share|improve this answer

In the scenario where you have many keys, you will invariably run into the "Too many Authentication Failures" error. If you have a password, and want to simply use the password to login, here is how you do it.

To use ONLY password authentication and NOT use Public-key, and NOT use the somewhat misleading "keyboard-interactive" (which is a superset including password), you can do this from the command line:

ssh -o PreferredAuthentications=password
share|improve this answer

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 '14 at 13:14
Putting IdentitiesOnly yes in the global section of ssh_config is what did it for me. Thanks! – jamix Mar 20 '15 at 11:04
Thank you for the detailed comment. I used to use ('\' for newline) Host * \ IdentityFile ~/.ssh/mykey as a configuration option, and at first it seemed odd that having a different entry for a specific site, e.g. Host special \ IdentityFile ~/.ssh/specialkey \ IdentitiesOnly yes continued to supply mykey instead of specialkey. It certainly was unclear, until I realized (from your answer) that the IdentityFile entries are stacked in an order of evaluation and the last-defined one will be used. Removing IdentityFile ~/.ssh/mykey solved the issue, and the correct, single key was used. – Ryder Oct 5 '15 at 15:28

You had the answer all along (almost):

Host *
PreferredAuthentications keyboard-interactive,password

Worked for me.

share|improve this answer
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


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.