Many people around me don’t know about the magical ~/.ssh/config file. If you are among of them, just read on and pretend you knew it all the way. ;)
Here’s a simple, yet useful sample that shows just the two most essential features that you can start using today:
1 2 3 4 5
What do we see here?
- ~/.ssh/config is a plain-text file. Note that it’s file permissions should be “600” (read/write by owner only), and ~/.ssh directory permissions must be “700”. It is important. If they are too permissive, SSH won’t trust your configuration.
- The file consists of sections that start with the “Host” declaration. Each section corresponds to one host specified either by name or IP address.
- Statements in the sections are indented (traditionally with 3 spaces).
- “Port” statement suggests the port number to use when connecting to the given Host.
- “IdentityFile” statement lets you use a non-default (id_rsa) private key. I see you burst into tears. Yes, you can have many keys for different occasions – personal and team; any number of them.
These are just few options that I find the most useful in my everyday practice, but feel free to explore it deeper.
One important thing I need to mention is that this configuration applies to absolutely all cases when you open the SSH connection by standard means, not just when SSH’ing somewhere directly. You can do SCP to transfer files, access remote repositories with SVN and GIT, deploy your developments with Capistrano and much more.