Configure ssh-key path to use for a specific host

When connecting via SSH my terminal wants to use id_rsa by default. I don't want to use that key for this particular server. So I am forced to specify the proper key path when connecting:

This works to connect:ssh -i /Users/myuser/.ssh/mykey

But I would prefer to use the following to connect:ssh

My Question: Is there a way to indicate in known_hosts or other config that SSH should use the key located at /Users/myuser/.ssh/mykey when serveruser is connecting to server.com?

Thanks!

1

2 Answers

One option you could consider would be to user the .ssh/config file.

Example: .ssh/config

Host server.com HostName server.com User serveruser IdentityFile /Users/myuser/.ssh/mykey

By doing this you could execute "ssh server.com". The config file would use the specified Username and Identity File.

2

An additional option would be to use ssh-agent.

If you add all of your identities to it

ssh-add .ssh/id_rsa
ssh-add .ssh/mykey

When you connect to the remote host, the one that works is the one that is used.

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