Tag Archives: ControlMaster

Use SSH config file to easely connect to servers via alias names

I don’t have a very good memory and always have problems remembering my servers names when connecting to them via SSH. I usually used this “solution”:

$ history | grep ssh

Yep… not very neat. A friend (follow him, you’ll learn lots of things!) told me I could use Control+Shift+R in the terminal and It was like “OMG! This is great!”. After pressing that key combination you can start typing a command and you’ll get matches to previous commands with that text, so all I had to do was type “ssh” and then press enter. Magic!


But today I found another way that involved using the ~/.ssh/config file. The first step is to create this file in the correct place and, most important, with the correct permissions:

$ touch ~/.ssh/config
$ chmod 600 ~/.ssh/config

Now lets suppose we usually connect to a server called vps1.hostingsolution.com with a user named myuser. We can add this to ~/.ssh/config:

Host vps1
  HostName vps1.hostingsolution.com
  User myuser

And here comes the cool part: now we can connect to this server with that user name by just typing this:

$ ssh vps1

That’s it. And of course you can add more and more configurations to it:


And if we also have enabled the connection using public/private keys we don’t even have to write a password.

This file is very heplful for other things too. For example you can make speed up SSH if you configure ControlMaster because it enables the sharing of multiple sessions over a single network connection.

Host *
  ControlMaster auto
  ControlPath ~/.ssh/ssh_mux_%h_%p_%r

If you get this error while connecting after configuring this it’s very likely because the ControlPath route does not exists or is write protected:

muxserver_listen bind(): No such file or directory

Ref: http://mattryall.net/blog/2008/06/ssh-favourite-hosts