Mac: Creating Shortcut Host Names When Connecting Over SSH in Terminal

If you’re on a Mac and want to connect to another computer over SSH via your Terminal, you can create a shortcut so that instead of typing

> ssh server1.ops.somedomain.com

you can just enter

> ssh server1

You can also specify which user you’d like to connect as. To set this up,

  1. open a Terminal window
  2. change to your ssh folder, i.e. cd .ssh
  3. create a config file, if one doesn’t already exist, touch config
  4. edit the config file, e.g. vi config
  5. add a record for each shortcut you’d like separated by a blank line, e.g.

Host server1
HostName server1.ops.somedomain.com

Host server2
User john
HostName server2.ops. somedomain.com

Exit your SSH connection and then reconnect using the shortcut, e.g.  > ssh server1