Read more

Defining host aliases in your SSH config

Arne Hartherz
May 30, 2011Software engineer at makandra GmbH

You probably already manage servers you often connect to inside the ~/.ssh/config file. What is nice: you may define alias names for hosts so that you can say something like ssh foobar-staging.

Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show archive.org snapshot

This is especially helpful for servers whose hostnames are hard to remember or who don't have a DNS record at all (and must be accessed via their IP address).

To achieve the above, you can define something like this in your ~/.ssh/config:

Host foobar-staging
  Hostname staging.example.com

Note that SSH will only match this for ssh foobar-staging and not for ssh staging.example.com. If you want that, add it to the Host row separated by a space character -- this way you can also define multiple aliases.

Host foobar-staging staging.example.com my-playground
  Hostname staging.example.com

Neat: The aliases will also be available in your bash as tab-completable arguments for the ssh command.

Posted by Arne Hartherz to makandra dev (2011-05-30 11:28)