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:
- Host zeus allows you to type “ssh zeus” instead of “ssh email@example.com” in the command line
- HostName is the box you’re connecting to
- User is your login name
- 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:
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.