Simplifying SSH Connections on Mac OSX (and Linux) with .ssh/config
If you’re in an environment where you need to constantly SSH into several development, test and production servers and didn’t know about this trick, you’ll find this handy.
The issue I have with connecting to various machines remotely is that they are all on different ports, using different keyfiles and using various IP address that I can hardly remember. Typically, I’ll use something like this command to connect to each of them:
ssh -i ~/.ssh/keyfile email@example.com -p 18098
Now imagine tens more of them with various IP address, port number and keyfile. After a while you’ll either end up writing an alias in your .bash_profile, or start saving all these information in a notepad. Although both options are fine (if you take proper precautions), I love the simplicity of a magic file called ‘.ssh/config’
Basically, create a file called ‘config’ in your ‘.ssh’ directory (or if you prefer, folder) in your home directory (you can type cd ~/.ssh to get there quickly). Now for every connection profile you have, you can put these information in the file:
Once you’re done, you can simply connect to this host by typing:
$ ssh Production
Repeat this sets of configuration for every host you have, and you’re set!