How can multiple private keys be used with ssh?

You can set this up in your ~/.ssh/config file. You would have something like this:

Host server1
IdentityFile ~/.ssh/key_file1

Host server2
IdentityFile ~/.ssh/key_file2

man ssh_config is a reference


There are a few options.

  1. Load both keys into your ssh agent using ssh-add. Then both keys will be available when connecting to both servers

  2. Create your $HOME/.ssh/config file and create a Host section for server1 and another for server2. In each Host section, add an IdentityFile option pointing to the appropriate private key file


Besides 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 use

$ ssh -i privatekey1 user@server1

e.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