I was able to setup ssh to use private/public key authentication. Now I am able to do
ssh user@server1
And it logs on with the private key. Now I want to connect to another server and use a different key. How do set it up so
ssh user@server1
uses privatekey1
ssh user@server2
and uses privatekey2
You can set this up in your
~/.ssh/config
file. You would have something like this:man ssh_config
is a referenceThere are a few options.
Load both keys into your ssh agent using
ssh-add
. Then both keys will be available when connecting to both serversCreate your
$HOME/.ssh/config
file and create aHost
section for server1 and another for server2. In eachHost
section, add anIdentityFile
option pointing to the appropriate private key fileBesides the (preferable) option of adding both keys in
$HOME/.ssh/config
(note that this requires appropriately setting attributes of$HOME/.ssh
and$HOME/.ssh/config
), you can usee.g.
I learned this by way of solving this more complex situation: Multiple ssh access types from a given user1/client to the same user2/server