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!

Advertisements

Author: drewsymo

Developer

2 thoughts on “How to Create an SSH Config File Shortcut on Mac OSX / Linux”

  1. why can’t anyone actually explain how to add the config file – not just cd to it????? I want to know how to add the config file as your title suggests! There isn’t one!

    Like

    1. Hey Nick,

      In terms of creating the config file, the first command will do this for you once you’ve saved it:

      vi ~/.ssh/config

      If you’d prefer not to do it this way, you can create a blank file using the touch command:

      touch ~/.ssh/config

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s