Manage your hostnames with SSH Config

Logging into a remote server from your terminal could be a pain if you use the ssh command with the options of your private key, username and stuff. Fortunately, you can create a config file for your hostnames.

Let’s say that I want to log on a remote server called dummy.com with the username flotz and a private key found in ~/.ssh/private.key. The SSH command would be:

ssh -l flotz -i ~/.ssh/private.key dummy.com
# Or even
ssh -i ~/.ssh/private.key flotz@dummy.com

Well, I will make my life easier by creating a config file for that hostname:

vi ~/.ssh/config

Host dummy
    Hostname dummy.com
    IdentityFile ~/.ssh/private.key
    User flotz

And now I can remotely connect by simply typing ssh dummy.

You might want to add more options like the Port or maybe the ForwardAgent if you work with git.

# in ~/.ssh/config
Host dummy
    Hostname dummy.com
    IdentityFile ~/.ssh/private.key
    User flotz
    Port 1234
    ForwardAgent yes

Pro-tip: you can add more than one Host as long as you separate them with whitespaces:

# in ~/.ssh/config
Host dummy dummy2
    Hostname dummy.com
    IdentityFile ~/.ssh/private.key
    User flotz