SSH aliases

I constantly connect to linux or unix machines using ssh and it can get a little bothersome typing out the IP address repeatedly. Here is the typical syntax to connect to a linux box (random IP address)

ssh username@111.11.11.1

Now imagine typing this again and again. Thats where the ssh config file comes to the rescue. You can create aliases to make your connections easy. The template for the config file ~/.ssh/config is

Host domain
  HostName domain.com
  User username

The HostName can be either an IP address or an actual hostname. So for our example above our config file ~/.ssh/config will be

Host myserver
  HostName 111.11.11.1
  User username

So now all you have to do is type the following on your command prompt to directly connect and get prompted for a password.

ssh myserver

You can create as many aliases as you want. You can also override the settings of the config file on the command line. For instance if you want to connect using a different user, you can do the following

ssh diff_user@myserver

You can also specify your SSH keys for the server in your config file as shown below so you don’t have to enter your password

Host myserver
  HostName 111.11.11.1
  User username
  IdentityFile ~/.ssh/id_dsa

Click here or here to read how to generate and use SSH keys.