Save time using SSH Config

James Hamann
2 min readApr 11, 2020

If you manage a lot of servers and are remotely accessing them via SSH, you’ll know it’s a pain to remember and type out the full command. Especially if there’s multiple keys for each server that you want to connect to. Currently we’d need to type the command ssh -i /path/my-key-pair.pem endpoint-ip.me.com , making sure the path and IP/endpoint is accurate. This is laborious and unnecessary.

Thankfully, there’s a shortcut.

Using a config file in your ~/.ssh directory, we can create aliases. Each of these aliases are named and mapped to a remote server. This is done by providing each alias block with a set of keys and values.

Let’s start by creating our config file.

#bash$ cd ~/.ssh
$ atom config # or whatever editor you use
# If this file doesn't exist, create it using the 'touch' command, eg: $ touch config
#~/.ssh/configHost test
HostName 12.34.56.789
User username
IdentityFile ~/path/to/your/.pem

The alias block is named using the Host key. Then, as you would when using the SSH command, enter the HostName, User and IdentityFile file path. Save, and then close the file.

Done! It’s that simple.

Next time you’re SSHing into your servers simply use the command ssh myaliasname .

Thanks for reading. Hit 👏 if you like what you read and be sure to follow to keep up to date with future posts.

--

--