With ssh -i <private key filename> you can instruct ssh to use an extra private key to try authentication.

The documentation is not clear on how to explicitly use only that key.


You can use the IdentitiesOnly option:

ssh -o "IdentitiesOnly=yes" -i <private key filename> <hostname>

| improve this answer | |
  • 13
    actually 'IdentitiesOnly' disables prompting ssh-agent, but still offers defaults and ssh_config'd keys. – rogerovo Jun 25 '14 at 6:55
  • 2
    The important thing for me was that it does not look in e.g. my ~/.ssh directory for keys to try. – Herman van Rink Jun 25 '14 at 8:50
  • Thanks! I needed the -o "IdentitiesOnly=yes" bit to prevent ssh-agent from overriding the private key specified. – user2708667 Mar 19 '19 at 20:10
  • This is super handy for determining which key works with a given host when you have keys cached in ssh-agent. The only way I could figure it out without this flag was to use strace to dump the IO, which was pretty tedious. – Wil Jun 5 '19 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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