Howto force ssh to use a specific private key?

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.

0

2 Answers

You can use the IdentitiesOnly option:

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

6

An alternative could be to generate a pair of keys using

ssh-keygen

and create a special configuration for the specified host and corresponding private key

Edit ~/.ssh/config

Host handy_server HostName x.y.z.w IdentityFile ~/.ssh/handy.pub IdentitiesOnly yes User userk Port 22
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like