How to set up an SSH config file in Mac OS X

If you regularly ssh onto more than one remote machine, setting up a config file can make your life a bit easier. It’s also surprisingly easy to get set up.

First, navigate to your ~/.ssh directory and take a look at what’s in there. You may not have much, or it might have SSH keys, or even directories with SSH keys inside of them.

Do you see a file called config? If not, create it.

In the file, you can create entries for your different hosts. Here’s an example:

Host zeus
   HostName dev.zeus.com
   User me
   IdentityFile ~/.ssh/zeus/id_rsa

The above means the following:

  1. Host zeus allows you to type “ssh zeus” instead of “ssh me@dev.zeus.com” in the command line
  2. HostName is the box you’re connecting to
  3. User is your login name
  4. IdentityFile points to the SSH key to use for this connection (if you have one)

If you have more than one box you SSH into, just add it to the file. Your config file might look like this if you had three boxes you connected to:

Host zeus
HostName dev.zeus.com
User me
IdentityFile ~/.ssh/zeus/id_rsa

Host homer
HostName homer.com
User anotherUser

Host abby
HostName my.abby.com
User Abby
IdentityFile ~/.ssh/abby/id_rsa

Notice that the second Host doesn’t specify an SSH key — if you don’t use an SSH key to authenticate, then there’s no need for the IdentityFile line.

There are also other variables you can specify in the config file, you can read about them here.