Multi-SSH key profile config Linux/MacOS

What if you need to SSH with key authentication to more than a single host from your laptop or server? This came up while rebuilding a host, its worth sharing…

If you only ssh to a single host, you’d never have an issue, but when you need to generate a second key, you’ll need to create a config file in your ssh directory. The config file can then know where to find the private key to match for your ssh session on the remote host. Here is how this works. I have subfolders for each server and use the config file to point to them (You can configure this how you wish, just ensure you have rights to the path!).

Files and folder layout:

/Users/Gabe/.ssh/Server1/(contains id_rsa and files)
/Users/Gabe/.ssh/Server2/(contains id_rsa and files)

The config file is placed here and does the magic:


Here is what is the config file looks like when firing up a terminal:

# nano /Users/Gabe/.ssh/config



To connect an ssh session, simply type:

# ssh Server1

Let’s say we needed to add a third local key-pair entry to an SSH host at for remote user named Spiderman. It would look like this:






Side note – probably best to configure limited permissions on your private id_rsa files!

# sudo chmod 600 /path/to/id_rsa