How to Create an SSH Config File Shortcut on Mac OSX / Linux

Ever wondered how people just type ssh myserver and it automagically connects? I’ll show you how to on Mac OSX / Linux.

Create an SSH Config File

To create an SSH config file, open your terminal and issue the following command:

vi ~/.ssh/config

If you’re a little unsure of vi, replace it with your favourite editor, such nano.

In the same file, copy and paste the following lines:

Host myserver
   HostName myserver.com
   User root

You’re done! Save the file and open your new SSH session by typing:

ssh myserver

What if I want to specify a Public / Private Key (IdentityFile) to connect?

If you are using Public Key authentication to connect to myserver, just amend your SSH config file with the IdentyFile directive:

Host myserver
   HostName myserver.com
   User root
   IdentityFile ~/.ssh/id_rsa

Where id_rsa is your private key file.

Like this article? Let me know in the comments below!